Audio 对象用于表示HTML 元素。
音频对象是HTML5 中的一个新对象。
句法:
- 创建
- 访问
属性值:
Value | Description |
---|---|
audioTracks | It is used for returning an AudioTrackList object representing available audio tracks. |
autoplay | It is used for setting or returning whether the audio should start playing as soon as it is ready. |
buffered | It is used for returning a TimeRanges object representing the buffered parts of an audio. |
controller | It is used for returning the MediaController object representing the current media controller of an audio. |
controls | It is used for setting or returning whether an audio should have controls displayed (play/pause etc). |
crossOrigin | It is used for setting or returning the CORS settings of an audio. |
currentSrc | It is used for returning the URL of the current audio. |
currentTime | It is used for setting or returning the current playback position in an audio (in seconds). |
defaultMuted | It is used for setting or returning whether the audio should be muted by default. |
defaultPlaybackRate | It is used for setting or returning whether the search field is read-only, or not. |
duration | It is used for returning the length of an audio(in seconds). |
ended | It is used for returning whether the playback of the audio has ended. |
error | It is used for returning a MediaError object representing the error state of the audio. |
loop | It is used for setting or returning whether the audio should start playing over again, every time it is finished. |
mediaGroup | It is used for setting or returning the name of the media group the audio(s) is a part of. |
muted | It is used for setting or returning whether the sound should be turned off. |
networkState | It is used for returning the current network state of an audio. |
paused | It is used for setting or returning whether an audio is paused. |
playbackRate | It is used for setting or returning the speed of the audio playback. |
played | It is used for returning a TimeRanges object representing the played parts of the audio. |
preload | It is used for setting or returning the value of the preload attribute of an audio. |
readyState | It is used for setting or returning the current ready state of an audio. |
seekable | It is used for returning a TimeRanges object representing the seekable parts of an audio. |
seeking | It is used for returning whether the user is currently seeking in the audio. |
src | It is used for setting or returning the value of the src attribute of an audio. |
textTracks | It is used for returning a TextTrackList object representing the available text tracks. |
volume | It is used for setting or returning the audio volume of an audio. |
音频对象方法:
Value | Description |
---|---|
addTextTrack() | It is used for adding a new text track to the audio. |
canPlayType() | It is used for checking whether the browser can play the specified audio type. |
fastSeek() | It is used for seeking to a specified time in the audio player. |
getStartDate() | It is used for returning a new Date object, representing the current timeline offset. |
load() | It is used for re-loading the audio element. |
play() | It is used for start playing the audio. |
pause() | It is used for pausing the currently playing audio. |
下面的程序说明了音频对象:
示例 1:创建
Audio Object
GeeksforGeeks
Audio Object
Double Click the "Create"
button to create an Audio Object.
输出:
- 点击按钮前:
- 点击按钮后:
示例 2:访问
Audio Object
GeeksforGeeks
Audio Object
Double-click the "Access Audio" button
to get the duration of the audio, in seconds.
输出:
- 点击按钮前:
- 点击按钮后:
支持的浏览器: HTML支持的浏览器 |下面列出了DOM 音频对象:
- 谷歌浏览器
- IE浏览器
- 火狐
- 歌剧
- 苹果Safari