Android 2.3 and the HTML5 Audio API

I ran into an issue with Android 2.3 and the HTML5 audio element. Evidently, you cannot reuse an instance of the Audio class. For example, if I define a sound, and play it:

var aud = new Audio();
aud.src = 'mysound.mp3';
aud.play();

And then on finish try to reuse the variable:

aud.src = 'mysecondsound.mp3';
aud.play();

The first sound plays a second time. For it to work, you have to destroy the first variable to reuse it.

This seems to be fixed in Android 4.2. I don’t have any intermediate versions in which to test.

What makes this bug annoying is that in Android 4.2, in order to play audio onFinish, you MUST reuse the variable. The same applies to iOS, by the way. So now we have to do user agent version checking in order to support both…

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>