I am creating a basic sound application that has several buttons that play sounds. I use PhoneGap / Cordova and I use the PhoneGap Build service to compile the code in the APK. At first, I used simple HTML5 tags <audio>that worked perfectly in the desktop browser, as well as in the Android browser, but when they were packaged in the PhoneGap application, no sounds were played.
I looked around and saw some mention of the need to use the Media API in PhoneGap instead of the standard HTML5 sound, so I switched to it with the following code changes.
I have the following function:
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 a handler onclicksimilar to this ...
onclick="doPlay('sound1');"
, index.html, sound1.mp3, sound2.mp3 .. alertDismissed() , .
. . 'Success' 'Error'. , notification media.
. ?
. @simon-macdonald, ( "/android_asset/www/" ), , . , /.: - (