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 name | Description |
---|---|
abort | Sent when playback is aborted; for example, if the media is playing and is restarted from the beginning, this event is sent. |
| Sent 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 . |
| Sent 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. |
| The 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. |
| 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. |
encrypted | The user agent has encountered initialization data in the media data. |
| Sent when playback completes. |
error | Sent when an error occurs. The element's error attribute contains more information. See HTMLMediaElement.error for details. |
interruptbegin | Sent 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. |
interruptend | Sent 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. |
| The first frame of the media has finished loading. |
| The media's metadata has finished loading; all attributes now contain as much useful information as they're going to. |
| Sent when loading of the media begins. |
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. |
| Sent when the playback state is changed to paused (paused property is true ). |
| Sent when the playback state is no longer paused, as a result of the play method, or the autoplay attribute. |
| Sent 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 . |
| Sent 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. |
| Sent when the playback speed changes. |
| Sent when a seek operation completes. |
| Sent when a seek operation begins. |
| Sent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming. |
| Sent 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. |
| The time indicated by the element's currentTime attribute has changed. |
| Sent when the audio volume changes (both when the volume is set and when the muted attribute is changed). |
| Sent 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论