goldfire / howler.js

Javascript audio library for the modern web.
https://howlerjs.com
MIT License
23.87k stars 2.23k forks source link

html5 audio doesnt play in safari desktop #987

Closed indexofrefraction closed 6 years ago

indexofrefraction commented 6 years ago

i noticed that html5 audio does not play in safari desktop (maybe the same in chrome)

play() is called but there is no sound and no console output (promise errors or something)

(note: without html5:true everything works fine)

goldfire commented 6 years ago

The HTML5 samples on https://howlerjs.com are working for me in Safari. Do you have a sample of something that isn't working?

indexofrefraction commented 6 years ago

after a lot of tests i can say

is there anything that could interfere with html5 playback?

indexofrefraction commented 6 years ago

if i go to tests/js/core.html5audio.js, remove the click event listener and just start the demo, i get the same behaviour

in my website i have clicks before i start the (html5) sounds.. does it need a play() inside the click event?

themoonrat commented 6 years ago

Yes. Most browsers these days restrict usage of audio unless an initial sound was played within a click event. This used to be restricted to mobile, but it's coming into desktop land too

indexofrefraction commented 6 years ago

ok, but is there a way to determine if this has happened already? can i know if i can play html5 or not?

a) either generally to determine the state b) from an already started howl. if it is really playing or not

for b) howler sound.playing() reports true, even if it isnt playing

goldfire commented 6 years ago

Yes, unfortunately, Safari's autoplay policies require that the sound is played within a user interaction like a click. The unlock method we have in howler won't work for this, so you'll have to make it work on your application end.