Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

HTML audio/video

May 04, 2021 HTML Reference Manual

Table of contents

HTML audio/video DOM reference manual

HTML5 DOM provides methods, properties, and events for the elements of slt;audio> and slt;video?gt;

These methods, properties, and events allow you to use JavaScript to manipulate the elements.

HTML audio/video method

方法 描述
addTextTrack() 向音频/视频添加新的文本轨道。
canPlayType() 检测浏览器是否能播放指定的音频/视频类型。
load() 重新加载音频/视频元素。
play() 开始播放音频/视频。
pause() 暂停当前播放的音频/视频。

HTML audio/video properties

属性 描述
audioTracks 返回表示可用音频轨道的 AudioTrackList 对象。
autoplay 设置或返回是否在加载完成后随即播放音频/视频。
buffered 返回表示音频/视频已缓冲部分的 TimeRanges 对象。
controller 返回表示音频/视频当前媒体控制器的 MediaController 对象。
controls 设置或返回音频/视频是否显示控件(比如播放/暂停等)。
crossOrigin 设置或返回音频/视频的 CORS 设置。
currentSrc 返回当前音频/视频的 URL。
currentTime 设置或返回音频/视频中的当前播放位置(以秒计)。
defaultMuted 设置或返回音频/视频默认是否静音。
defaultPlaybackRate 设置或返回音频/视频的默认播放速度。
duration 返回当前音频/视频的长度(以秒计)。
ended 返回音频/视频的播放是否已结束。
error 返回表示音频/视频错误状态的 MediaError 对象。
loop 设置或返回音频/视频是否应在结束时重新播放。
mediaGroup 设置或返回音频/视频所属的组合(用于连接多个音频/视频元素)。
muted 设置或返回音频/视频是否静音。
networkState 返回音频/视频的当前网络状态。
paused 设置或返回音频/视频是否暂停。
playbackRate 设置或返回音频/视频播放的速度。
played 返回表示音频/视频已播放部分的 TimeRanges 对象。
preload 设置或返回音频/视频是否应该在页面加载后进行加载。
readyState 返回音频/视频当前的就绪状态。
seekable 返回表示音频/视频可寻址部分的 TimeRanges 对象。
seeking 返回用户是否正在音频/视频中进行查找。
src 设置或返回音频/视频元素的当前来源。
startDate 返回表示当前时间偏移的 Date 对象。
textTracks 返回表示可用文本轨道的 TextTrackList 对象。
videoTracks 返回表示可用视频轨道的 VideoTrackList 对象。
volume 设置或返回音频/视频的音量。

HTML audio/video events

Event Describe
abort Triggered when the loading of audio/video has been abandoned.
canplay Triggered when the browser can start playing audio/video.
canplaythrough Triggered when the browser can play without pausing for buffering.
durationchange Triggered when the length of audio/video has changed.
emptied Triggered when the current playlist is empty.
ended Triggered when the current playlist is over.
error Triggered when an error occurs during audio/video loading.
loadeddata Triggered when the browser has loaded the current frame of audio/video.
loadedmetadata Triggered when the browser has loaded metadata for audio/video.
loadstart Triggered when the browser starts looking for audio/video.
pause Triggered when audio/video has been paused.
play Triggered when audio/video has started or is no longer paused.
playing Triggered when audio/video is ready after it has been paused or stopped due to buffering.
progress Triggered when the browser is downloading audio/video.
ratechange Triggered when the playback speed of the audio/video has changed.
seeked Triggered when the user has moved/jumped to a new location in the audio/video.
seeking Triggered when the user starts moving/jumping to a new location in the audio/video.
stalled Triggered when the browser tries to get media data, but the data is not available.
suspend Triggered when the browser deliberately does not obtain media data.
timeupdate Triggered when the current playback position has changed.
volumechange Triggered when the volume has changed.
waiting Triggered when the video stops because it needs to buffer the next frame.