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 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.
精彩评论