Skip to content

Instantly share code, notes, and snippets.

@rainyjune
Last active December 15, 2015 21:19
Show Gist options
  • Save rainyjune/5325346 to your computer and use it in GitHub Desktop.
Save rainyjune/5325346 to your computer and use it in GitHub Desktop.
Fix HTML5 audio playback issue on Android 2.3 default browser
<audio id="a" controls>
<source src="http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3" type="audio/mpeg">
</audio>
<script>
var a = document.getElementById('a');
var playFix = false;
var playFixRequired = true;
a.addEventListener('play', function() {
if (playFixRequired) {
playFix = true;
} else {
a.play();
}
}, false);
a.addEventListener('durationchange', function() {
if(playFixRequired && a.duration != 6000) {
playFixRequired = false;
if(playFix) {
playFix = false;
a.pause();
a.play();
}
}
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment