I'm creating an android web app and it's simple thing. I have a button and I want it to play a sound when clicked. I'v searched a lot and actually no proper solution that could help me out.
I'm a newbie on this part and I really have no idea how I can play my sound.
any help will be appreciated.
Edited : I installed media api on cordova : var media = new Media(src, mediaSuccess, [mediaError], [mediaStatus]);
this is my html part :
<a href="#" id="applaud"><img src="images/applaud.png"></a></li>
this is the javascript part :
$("#applaud").bind('tap', function() {
var media = new Media("lib/sounds/hooray.mp3", mediaSuccess);
media.play();
});
BTW I'm using jQuery Mobile for this application. Should I do anything else.
Thanks to those who answered my questions.
Update : I tried this code too ->
function playAudio(id) {
var audioElement = document.getElementById(id);
var url = audioElement.getAttribute('src');
var my_media = new Media(url,
// success callback
function () { alert("success"); },
// error callback
function (err) { alert("error"); }
);
// Play audio
my_media.play();
}
and then in my html it will be like this :
<a href="#" id="applaud" onclick="playAudio('/android_asset/www/lib/sounds/hooray.mp3');"><img src="images/applaud.png"></a>
still nothing, I even revert my cordova to version 3.1 but nothing guys I really need help.