I'm building a basic soundboard-like app which has a few buttons that play sounds. I'm using PhoneGap/Cordova and I'm using the PhoneGap Build service to compile the code to APK. At first, I was using simple HTML5 <audio>
tags which worked fine in the desktop browser as well as the Android browser, but when packaged into the PhoneGap app, no sounds were being played.
I looked around and saw some mentions of having to use the Media API in PhoneGap instead of standard HTML5 audio, so I switched to that with the following code changes.
I have the following function in place:
function doPlay(soundId) {
var my_media = new Media("/android_asset/www/"+soundId+".mp3",
function() {
navigator.notification.alert('Success!', alertDismissed);
},
function(err) {
navigator.notification.alert('Error!', alertDismissed);
});
my_media.play();
}
Each button has an onclick
handler similar to this...
onclick="doPlay('sound1');"
The files are in the same directory as the index.html
, called sound1.mp3
, sound2.mp3
and so on. And the function alertDismissed()
has also been defined, but it's empty.
However, it still does not work. There is no sound on click. There is no 'Success'
or 'Error'
message either. Yes, I've got notification
and media
permissions requested.
I'm quite stumped here. Any ideas?
Update: As suggested by @simon-macdonald, I put a full path to the local files ("/android_asset/www/"), but that still hasn't gotten the app to work. No sound, no error/success alerts. :-(