Question

I have developed an Android Audio Application that works perfectly using html5 Audio. However on some Phones the Audio will simply not play at all.

I am using simple HTML5 feature.

Tried all sort of things, like multiple play() commands, pause() & play, load() etc but nothing happens.

I have got hold of one such mobile for a day which is running Android 2.3.6 and I am unable to make it work. Any help would be highly appreciated.

Was it helpful?

Solution

I have found a solution. This is what worked for me:

sPlay = document.getElementById("audioplayer");
sPlay.src = '';
sPlay.src = "myAudio.mp3";
sPlay.load();
sPlay.addEventListener("load", function() { 
  sPlay.play(); 
}, true);       

I also changed

<source src="none" type="audio/mpeg">

to

<source src="none" type="audio/mp3">

My guess is the devices running the old Android version are slow. When the play() command is issued in a normal manner, the system is still processing the load() command. As the Audio is still not loaded it doesn't get played. After using an addEventListener for "load" it started working perfectly, as if the problem was not there in the first place :-)

Hope this helps others.

Thanks!

==== UPDATE ========

I have further modified event listener to "canplay" as "load" appears to be working on old devices only:

sPlay.addEventListener("canplay", function() { 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top