"pause" 事件是否在任何类型的音频停止时调用?
Is "pause" event called on any kind of audio stop?
MDN 说:
The pause event is sent when a request to pause an activity is handled
and the activity has entered its paused state, most commonly after the
media has been paused through a call to the element's pause() method.
但是,如果音频因为停顿或事件结束而停止怎么办。
还会触发pause
事件吗?或者我还应该对 stalled
和 ended
执行操作吗?
音频暂停事件
答案是暂停事件仅在调用 pause()
方法之后或在 ended
或 seeking
事件之前发出。 seeking 事件在轨道位置改变时发生,这会导致播放器在暂停和播放之间切换。
暂停事件不会在 stalled
或 waiting
事件之后发出,因为音频仍处于播放状态。此外,当音频 src 更改时,它会停止播放器,但不会发出暂停事件。
w3.org event specifications 没有提供太多细节,实现可能因浏览器而异。
运行 用于在浏览器上监视音频事件的代码段。
"audioprocess,canplay,canplaythrough,complete,durationchange,emptied,ended,loadeddata,loadedmetadata,pause,play,playing,ratechange,seeked,seeking,stalled,suspend,timeupdate,volumechange,waiting".split(",").forEach(name => {
player.addEventListener(name, (e) => monitor.innerHTML= e.timeStamp.toFixed(2) + ": " + e.type + "\n" + monitor.innerHTML);
});
<small>Click the audio controls to monitor events:</small><br/>
<audio id="player" controls preload="false" src="http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg" type="audio/ogg">
</audio>
<textarea id="monitor" rows=6 style="width:100%"></textarea>
MDN 说:
The pause event is sent when a request to pause an activity is handled and the activity has entered its paused state, most commonly after the media has been paused through a call to the element's pause() method.
但是,如果音频因为停顿或事件结束而停止怎么办。
还会触发pause
事件吗?或者我还应该对 stalled
和 ended
执行操作吗?
音频暂停事件
答案是暂停事件仅在调用 pause()
方法之后或在 ended
或 seeking
事件之前发出。 seeking 事件在轨道位置改变时发生,这会导致播放器在暂停和播放之间切换。
暂停事件不会在 stalled
或 waiting
事件之后发出,因为音频仍处于播放状态。此外,当音频 src 更改时,它会停止播放器,但不会发出暂停事件。
w3.org event specifications 没有提供太多细节,实现可能因浏览器而异。
运行 用于在浏览器上监视音频事件的代码段。
"audioprocess,canplay,canplaythrough,complete,durationchange,emptied,ended,loadeddata,loadedmetadata,pause,play,playing,ratechange,seeked,seeking,stalled,suspend,timeupdate,volumechange,waiting".split(",").forEach(name => {
player.addEventListener(name, (e) => monitor.innerHTML= e.timeStamp.toFixed(2) + ": " + e.type + "\n" + monitor.innerHTML);
});
<small>Click the audio controls to monitor events:</small><br/>
<audio id="player" controls preload="false" src="http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg" type="audio/ogg">
</audio>
<textarea id="monitor" rows=6 style="width:100%"></textarea>