I am trying to load audios dynamically in my project. I've used jPlayer, MediaElement.js and javascript create audio element. Everything is working fine in desktop browser but fails in android(OS 4.1+) browsers except firefox. I've attached the codes of various player that I tried.
jPlayer:
$("#jquery_jplayer_1").jPlayer({
ready: function (event) {
$(this).jPlayer("setMedia", {
mp3: "sample.mp3",
oga: "sample.ogg"
}).jPlayer("play");
},
swfPath: "js",
supplied: "mp3, oga",
wmode: "window",
smoothPlayBar: true,
keyEnabled: true,
ended : function(){
//$(this).jPlayer("stop" );
//$(this).jPlayer("playHead",100);
if(pCnt != tocArr.length-1){
$("#nextIns").css("display","block");
}
}
});
MediaElement.js:
audioPlayer = new MediaElementPlayer("#player", {
pauseOtherPlayers: false,
success: function (mediaElement) {
var sources = [{ src: "sample.mp3" }];
mediaElement.setSrc("sample.mp3");
mediaElement.pause();
mediaElement.load();
//mediaElement.play();
}
});
javascript:
I have added audio tag in html page and added the below code in my JS
JS:
audioElement = document.getElementById('player');
audioElement.pause();
audioElement.setAttribute('src', 'sample.mp3');
audioElement.load();
audioElement.play();
I don't know where I am going wrong. Please guide me on this.