Archive

Posts Tagged ‘Chrome’

Android Chrome does not allow applications to play HTML5 audio without an explicit action by the user

February 22, 2014 Leave a comment

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/

I have also put this work around into simple-audio which is a JavaScript module to make playing audio in the browser easier.