I try to play an mp3 file. This works if I change the path to the file on my local webserver, but if I run this on an Android device the sound is not played and no error is
I had the same problem and finally got it working, with me the problem lied with the scope of my media variable. I got it working as follows:
(function () {
"use strict";
var media;
document.addEventListener('deviceready', onDeviceReady.bind(this), false);
function onDeviceReady() {
media = new Media("/android_asset/www/sounds/wat is je wens.mp3", null, function (e) {
alert('Media Error');
alert(JSON.stringify(e));
});
alert('deviceready')
};
function onStart() {
media.play();
alert('yay')
}
};
Essentially I made sure that the scope of my media variable was sort of global by declaring it outside of onDeviceReady, but that Media wasn't called before the deviceready event.