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

I've created a new audio element and can successfully load, play, pause, mute, etc. However, I not

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745041903a4607859.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信