Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html5 audio - canplay event doesn't fire on Safari (Mac Desktop)

I'm trying to play some audio through the html5 audio tag (using Buzz as a wrapper if that makes any difference).

Because the audio is timed to start with another event, I've been listening for the canplay event.

It works perfectly on Chrome and Firefox, but Safari doesn't trigger the canplay event.

I've added event handlers for all the possible audio events available and as far as I can tell it only fires the loadstart and loadedmetadata event.

When the loadedmetadata is triggered the audio element looks fine in the inspector, but that's where it stops.

I'm guessing that's the cause has something to do with the element set to not auto-play.. for some reason that seems to cause Safari to stop there (if I autoplay then all the events are triggered).

Are you getting the same problem and is there a way to not auto-play the sound but get the canplay event to fire?

My Safari version is 5.1.3 (7534.53.10)

like image 975
Ben Avatar asked Mar 29 '12 06:03

Ben


1 Answers

Ok, the work around the problem is simply to set the sound to auto-play and listen to the canplay event. When that triggers I can then pause it and wait for my other event to trigger.

Had to move the logic around a bit but that seems to work ok.

like image 115
Ben Avatar answered Sep 22 '22 20:09

Ben