vendredi 30 janvier 2015

HTML5 - Check if autoplay is allowed

My website plays background music with autoplay. I made it use my custom controls for play and pause. Now, I'd like to set the initial state according to what is going on. If the music is about to play for real, it should show pause icon, otherwise (e.g. on mobile) play icon.


I would use audio.paused boolean value, but it's always false before the audio is loaded.


I would use audio.autoplay value, but it's always true for me, even on devices that don't support it.


Is there any clean way to know whether the audio will be played? I would like to keep it in sync with autoplay attribute, so if I decided to remove it, the state should always show play icon in the beginning.


Aucun commentaire:

Enregistrer un commentaire