Media events - Developer guides 编辑

Various events are sent when handling media that are embedded in HTML documents using the <audio> and <video> elements; this section lists them and provides some helpful information about using them.

Event nameDescription
abortSent when playback is aborted; for example, if the media is playing and is restarted from the beginning, this event is sent.
canplaySent when enough data is available that the media can be played, at least for a couple of frames.  This corresponds to the HAVE_FUTURE_DATA readyState.
canplaythroughSent when the readyState changes to HAVE_ENOUGH_DATA, indicating that the entire media can be played without interruption, assuming the download rate remains at least at the current level. It will also be fired when playback is toggled between paused and playing. Note: Manually setting the currentTime will eventually fire a canplaythrough event in firefox. Other browsers might not fire this event.
durationchangeThe metadata has loaded or changed, indicating a change in duration of the media.  This is sent, for example, when the media has loaded enough that the duration is known.
emptiedThe 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.
encrypted This is an experimental API that should not be used in production code.The user agent has encountered initialization data in the media data.
endedSent when playback completes.
errorSent when an error occurs.  The element's error attribute contains more information. See HTMLMediaElement.error for details.
interruptbeginSent when audio playing on a Firefox OS device is interrupted, either because the app playing the audio is sent to the background, or audio in a higher priority audio channel begins to play. See Using the AudioChannels API for more details.
interruptendSent when previously interrupted audio on a Firefox OS device commences playing again — when the interruption ends. This is when the associated app comes back to the foreground, or when the higher priority audio finished playing. See Using the AudioChannels API for more details.
loadeddataThe first frame of the media has finished loading.
loadedmetadataThe media's metadata has finished loading; all attributes now contain as much useful information as they're going to.
loadstartSent when loading of the media begins.
mozaudioavailableSent 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.
pauseSent when the playback state is changed to paused (paused property is true).
playSent when the playback state is no longer paused, as a result of the play method, or the autoplay attribute.
playingSent when the media has enough data to start playing, after the play event, but also when recovering from being stalled, when looping media restarts, and after seeked, if it was playing before seeking.
progressSent periodically to inform interested parties of progress downloading the media. Information about the current amount of the media that has been downloaded is available in the media element's buffered attribute.
ratechangeSent when the playback speed changes.
seekedSent when a seek operation completes.
seekingSent when a seek operation begins.
stalledSent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming.
suspendSent when loading of the media is suspended; this may happen either because the download has completed or because it has been paused for any other reason.
timeupdateThe time indicated by the element's currentTime attribute has changed.
volumechangeSent when the audio volume changes (both when the volume is set and when the muted attribute is changed).
waitingSent when the requested operation (such as playback) is delayed pending the completion of another operation (such as a seek).

You can easily watch for these events, using code such as the following:

var v = document.getElementsByTagName("video")[0];
v.addEventListener("seeked", function() { v.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 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:62 次

字数:9755

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文