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

最后都变了- 提交于 2019-12-13 14:51:22

问题


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)


回答1:


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.



来源:https://stackoverflow.com/questions/9920297/html5-audio-canplay-event-doesnt-fire-on-safari-mac-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!