Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

媒体相关事件

这篇翻译不完整。请帮忙从英语翻译这篇文章

在处理用<audio><video>标签嵌入到HTML文档中的媒体时,会触发多种事件。本章列出这些事件,并给出一些使用方法。

事件名称 描述
abort Sent when playback is aborted; for example, if the media is playing and is restarted from the beginning, this event is sent.
canplay 在媒体数据已经有足够的数据(至少播放数帧)可供播放时触发。这个事件对应CAN_PLAY的readyState。
canplaythrough 在媒体的readyState变为CAN_PLAY_THROUGH时触发,表明媒体可以在保持当前的下载速度的情况下不被中断地播放完毕。注意:手动设置currentTime会使得firefox触发一次canplaythrough事件,其他浏览器或许不会如此。
durationchange 元信息已载入或已改变,表明媒体的长度发生了改变。例如,在媒体已被加载足够的长度从而得知总长度时会触发这个事件。
emptied The media has become empty; for example, this event is sent if the media has already been loaded (or partially loaded), and the load() method is called to reload it.
ended 播放结束时触发。
error 在发生错误时触发。元素的error属性会包含更多信息。参阅Error handling获得详细信息。
loadeddata 媒体的第一帧已经加载完毕。
loadedmetadata 媒体的元数据已经加载完毕,现在所有的属性包含了它们应有的有效信息。
loadstart 在媒体开始加载时触发。
mozaudioavailable Sent when an audio buffer is provided to the audio layer for processing; the buffer contains raw audio samples that may or may not already have been played by the time you receive the event.
pause 播放暂停时触发。
play 在媒体回放被暂停后再次开始时触发。即,在一次暂停事件后恢复媒体回放。
playing 在媒体开始播放时触发(不论是初次播放、在暂停后恢复、或是在结束后重新开始)。
progress 告知媒体相关部分的下载进度时周期性地触发。有关媒体当前已下载总计的信息可以在元素的buffered属性中获取到。
ratechange 在回放速率变化时触发。
seeked 在跳跃操作完成时触发。
seeking 在跳跃操作开始时触发。
stalled Sent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
suspend 在媒体资源加载终止时触发,这可能是因为下载已完成或因为其他原因暂停。
timeupdate 元素的currentTime属性表示的时间已经改变。
volumechange 在音频音量改变时触发(既可以是volume属性改变,也可以是muted属性改变).。
waiting 在一个待执行的操作(如回放)因等待另一个操作(如跳跃或下载)被延迟时触发。

使用下面的代码,你可以很容易的观察到这些事件:

var v = document.getElementsByTagName("video")[0];
v.addEventListener("seeked", function() { document.getElementsByTagName("video")[0].play(); }, true);
v.currentTime = 10.0;

This example fetches the first video element in the document and attaches an event listener to it, watching for the seeked event, which is sent whenever a seek operation completes.  The listener simply calls the element's play() method, which starts playback.

Then, in line 3, the example sets the element's currentTime attribute to 10.0, which initiates a seek operation to the 10-second mark in the media.  This causes a seeking event to be sent when the operation begins, then a seeked event to be dispatched when the seek is completed.

In other words, this example seeks to the 10-second mark in the media, then begins playback as soon as that's finished.

Compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 3.5 (1.9.1) (Prior to Gecko 2.0, media events bubbled.) ? ? ?
load ? Removed in 3.6 (1.9.2) ? ? ?
mozaudioavailable 未实现 4.0 (2.0) 未实现 未实现 未实现
suspend ? 3.6 (1.9.2) ? ? ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ?
load ? ? ? ? ?
mozaudioavailable 未实现 4.0 (2.0) 未实现 未实现 未实现
suspend ? ? ? ? ?

 

文档标签和贡献者

 此页面的贡献者: esterTion, SudoKillMe, zilong-thu, ziyunfei, Anonymous
 最后编辑者: esterTion,