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

admin2025-04-19  1

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745041904a281593.html

最新回复(0)