Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25694] Hyperloop: Android- Cannot start native media Player.

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionInvalid
Resolution Date2018-01-24T12:20:58.000+0000
Affected Version/sRelease 7.0.1, Hyperloop 3.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterMotiur Rahman
AssigneeUnknown
Created2018-01-23T02:44:27.000+0000
Updated2018-08-06T17:37:06.000+0000

Description

Issue: Can not start native media player. It throws an error like Uncaught TypeError: Cannot read property 'start' of null Steps to Reproduce: 1. Create a new Alloy project. 2. Place the attached .mp3 file to the assets folder. 3. Then run the following test code.
var MediaPlayer = require('android.media.MediaPlayer');
var Activity = require('android.app.Activity'),
    am = require('android.content.res.AssetManager'),
    fis = require('java.io.FileInputStream');

var View = require('android.view.View');
var activity = new Activity(Ti.Android.currentActivity);
var context = activity.getApplicationContext();
var mPlayer = new MediaPlayer(activity);

var mPlayer = MediaPlayer.create(context, "five.mp3");

function doClick() {
	mPlayer.start();

}

$.containerWin.open();

<Alloy>
	<Window id='containerWin' class="container">
		<Label id="label" onClick="doClick">
			Hello, World
		</Label>
	</Window>
</Alloy>
[ERROR] :  TiExceptionHandler: (main) [692901,692901] ----- Titanium Javascript Runtime Error -----
[ERROR] :  TiExceptionHandler: (main) [0,692901] - In undefined:69,11
[ERROR] :  TiExceptionHandler: (main) [0,692901] - Message: Uncaught TypeError: Cannot read property 'start' of null
[ERROR] :  TiExceptionHandler: (main) [0,692901] - Source: 		mPlayer.start();
[ERROR] :  V8Exception: Exception occurred at undefined:69: Uncaught TypeError: Cannot read property 'start' of null
Thanks

Attachments

FileDateSize
five.mp32018-01-23T02:44:23.000+000036216

Comments

  1. Hans Knöchel 2018-01-24

    First of all, there are quite a few issues with the above code.
       var mPlayer = new MediaPlayer(activity);
       var mPlayer = MediaPlayer.create(context, "five.mp3");
       
    The mPlayer variable is declared twice, which doesn't make much sense. Also, the second parameter of the "create" method is from the type Uri or int, not String. Finally, the URL of the player item has to be constructed natively, which is not as simple as providing the file name as in Titanium. Please follow the native Android docs to do this, as this is no Titanium- or Hyperloop related issue.
  2. Eric Merriman 2018-08-06

    Closing as invalid. If incorrect, please reopen.

JSON Source