Last active
December 15, 2015 21:19
-
-
Save rainyjune/5325346 to your computer and use it in GitHub Desktop.
Fix HTML5 audio playback issue on Android 2.3 default browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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