Android Chrome does not allow applications to play HTML5 audio without an explicit action by the user
I was working a site that required to play some sound effects at different times and when testing on my Android phone, I was very surprised to find that only some of the sounds would play.
I assumed that there must be a restriction on bit rate or something else specific to the sound file as some played fine and others didn’t play at all, all using the same code.
I then stumbled across this chromium issue 178297 https://code.google.com/p/chromium/issues/detail?id=178297
It turns out there is a mobile specific restriction put in place to disable playback of media if not a direct result of user interaction.
Now I can see why this exists as I HATE auto play videos and ads and they would be even worse on mobile, however I have a valid use for this.
The reason only some of my sounds worked was some were triggered by a button click, while other were trigged by a URL hash change.
A button click is a user interaction / gesture but hash change is not.
Luckily Philip Jägenstedt has found a work around to the situation by using the first user interaction to “warm up” or initialise each audio element.
This then allows non user interaction events to use the elements moving forward.
His post on the issue, including his workaround is at http://blog.foolip.org/2014/02/10/media-playback-restrictions-in-blink/
Last night I have a talk at BrisJS, attempting to remove some of the magic and mystery around jQuery and its selection API.
I hope for those that attended it will help you to realise that it is not so scary and is quite readable.
The slides can be found here.
After having created this blog over a year ago, creating numerous drafts and never getting around to finishing them, I am determined to make time in my life to do this.
Over the next few weeks I hope to blog about some technical topics, mostly revolving around software development, although the will most likely be some off topic rants as well.
If you notice a period of time without some update someone yell at me either here or on Twitter @ButlerMaurice and ill get back to it ASAP.