[TIMOB-25694] Hyperloop: Android- Cannot start native media Player.
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | None |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2018-01-24T12:20:58.000+0000 |
Affected Version/s | Release 7.0.1, Hyperloop 3.0.1 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Motiur Rahman |
Assignee | Unknown |
Created | 2018-01-23T02:44:27.000+0000 |
Updated | 2018-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
File | Date | Size |
---|---|---|
five.mp3 | 2018-01-23T02:44:23.000+0000 | 36216 |
First of all, there are quite a few issues with the above code.
The
mPlayer
variable is declared twice, which doesn't make much sense. Also, the second parameter of the "create" method is from the typeUri
orint
, notString
. 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.Closing as invalid. If incorrect, please reopen.