最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - canplaythrough event and HTM5 audio: can anyone remove this event? - Stack Overflow

programmeradmin0浏览0评论

I've created a new audio element and can successfully load, play, pause, mute, etc. However, I noticed some browsers (FF, Opera) will always fire the canplaythrough event when I execute play(). Chrome has issues with this as well. But Safari behaves as expected... the event is fired only once after the readyState changes to HAVE_ENOUGH_DATA.

I also noticed no browsers will let me remove this event.

Constantly firing canplaythrough is annoying because I don't necessarily want to execute the handler attached to the canplaythrough event every time I play the audio file. I've also experienced some strange playback errors on Chrome whenever canplaythrough is fired more than once.

Can anyone shed some light on what's going on with canplaythrough and why it can't be removed after it's initially fired.

Thanks.

I've created a new audio element and can successfully load, play, pause, mute, etc. However, I noticed some browsers (FF, Opera) will always fire the canplaythrough event when I execute play(). Chrome has issues with this as well. But Safari behaves as expected... the event is fired only once after the readyState changes to HAVE_ENOUGH_DATA.

I also noticed no browsers will let me remove this event.

Constantly firing canplaythrough is annoying because I don't necessarily want to execute the handler attached to the canplaythrough event every time I play the audio file. I've also experienced some strange playback errors on Chrome whenever canplaythrough is fired more than once.

Can anyone shed some light on what's going on with canplaythrough and why it can't be removed after it's initially fired.

Thanks.

Share Improve this question asked Mar 5, 2011 at 15:30 VinceVince 5899 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

I've been able to remove the canplaythrough event in Chrome (and Safari, if I recall correctly.)

Code such as the example below seems to work for me:

// add event
audioElem.addEventListener("canplaythrough", displayHome, false);

// later remove event before triggering play
audioElem.removeEventListener("canplaythrough", displayHome, false);

Like you, I noticed some funky playback issues when I didn't remove the event in Chrome.

发布评论

评论列表(0)

  1. 暂无评论