audio object
Specifies the sound or audio content, such as music or effects, to be played in a document.
![]() ![]() |
Members
The audio object has these types of members:
Events
The audio object has these events.
| Event | Description |
|---|---|
| canplay |
Occurs when playback is possible, but would require further buffering. |
| canplaythrough |
Occurs when playback to end is possible without requiring a stop for further buffering. |
| durationchange |
Occurs when the duration attribute is updated. |
| emptied |
Occurs when the media element is reset to its initial state. |
| ended |
Occurs when the end of playback is reached. |
| loadeddata |
Occurs when media data is loaded at the current playback position. |
| loadedmetadata |
Occurs when the duration and dimensions of the media have been determined. |
| loadstart |
Occurs when Internet Explorer begins looking for media data. |
| pause |
Occurs when playback is paused. |
| play |
Occurs when the play method is requested. |
| playing |
Occurs when the audio or video has started playing. |
| progress |
Occurs to indicate progress while downloading media data. |
| ratechange |
Occurs when the playback rate is increased or decreased. |
| seeked |
Occurs when the seek operation ends. |
| seeking |
Occurs when the current playback position is moved. |
| stalled |
Occurs when the download has stopped. |
| suspend |
Occurs if the load operation has been intentionally halted. |
| timeupdate |
Occurs to indicate the current playback position. |
| volumechange |
Occurs when the volume is changed, or playback is muted or unmuted. |
| waiting |
Occurs when playback stops because the next frame of a video resource is not available. |
Methods
The audio object has these methods.
| Method | Description |
|---|---|
| canPlayType |
Returns a string that specifies whether the client can play a given media resource type. |
| load |
Resets the IHTMLMediaElement and loads a new media resource. |
| pause |
Pauses the current playback and sets paused to true. |
| play |
Loads and starts playback of a media resource. |
Properties
The audio object has these properties.
| Property | Description |
|---|---|
|
The autobuffer element is not supported by Internet Explorer 9. Use the preload element instead. | |
|
Gets or sets a value that indicates whether to start playing the media automatically. | |
|
Gets a collection of buffered time ranges. | |
|
Gets or sets a flag that indicates whether the client provides a set of controls for the media (in case the developer does not include controls for the player). | |
|
Gets the address or URL of the current media resource (video,audio) that is selected by IHTMLMediaElement. | |
|
Gets or sets the current playback position, in seconds. | |
|
Gets or sets the default playback rate when the user is not using fast foward or reverse for a video or audio resource. | |
|
Gets the duration, in seconds, of the current media resource, a | |
|
Gets information about whether the playback has ended or not. | |
|
Gets an IHTMLMediaError object representing the current error state of the media element. | |
|
Gets the earliest possible position, in seconds, that the playback can begin. | |
|
Gets or sets a flag that specifies whether playback should restart after it completes. | |
|
Gets or sets a flag that indicates whether the audio (either audio or the audio track on video media) is muted. | |
|
Gets the current network activity for the element. | |
|
Gets a flag that specifies whether playback is paused. | |
|
Gets or sets the current speed for the media resource to play. This speed is expressed as a multiple of the normal speed of the media resource. | |
|
Gets TimeRanges for the current media resource that has been played. | |
|
Gets or sets a hint to how much buffering is advisable for a media resource, even if autoplay is not specified. | |
|
Returns a TimeRanges object that represents the ranges of the current media resource that can be seeked. | |
|
Gets a flag that indicates whether the the client is currently moving to a new playback position in the media resource. | |
|
The address or URL of the a media resource (video, audio) that is to be considered. | |
|
Gets or sets the volume level for audio portions of the media element. |
Standards information
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 4.8.7
Remarks
Beginning with Internet Explorer 9, any audio or video content needs the correct mime type set on the server, or the files won't play. Internet Explorer 9and Internet Explorer 10support MP3 audio, and MP4 audio and video. WebM audio and video files can be supported by installing the WebM components from The WebM project. The following table shows the required settings for your web server to host these files correctly.
| Media file to serve | Extension setting | Mime type setting |
|---|---|---|
| Audio mp3 | mp3 | audio/mpeg |
| Audio mp4 | m4a | audio/mp4 |
| Audio WebM | webm | audio/webm |
| Video mp4 | mp4 | video/mp4 |
| Video webm | webm | video/webm |
Examples
The following code example plays an MP3-format audio file.
Using one of the following formats, type the name of an MP3-format audio file in the text box:
- Local file syntax: "file://C:\yourfilepath.mp3"
- Web file syntax: "http://webfilepath.mp3"
<title>Simple Audio Example</title>
<script type="text/javascript">
// Alternates between play and pause based on the value of the paused property
function togglePlay() {
if(document.getElementById("audio1")){
var audioElm = document.getElementById("audio1");
if (audioElm.paused == true){
playAudio(audioElm); // if player is paused, then play the file
}else{
pauseAudio(audioElm); // if player is playing, then pause
}
}
}
function playAudio(audioElm) {
document.getElementById("playbutton").innerHTML = "Pause"; // button text == Pause
//get file from text box and assign it to the source of the audio element
audioElm.src = document.getElementById('audioFile').value ;
audioElm.play();
}
function pauseAudio(audioElm) {
document.getElementById("playbutton").innerHTML = "play"; // button text == Play
audioElm.pause();
}
</script>
</head>
<body>
<div>
<audio id="audio1" style="width:25%" controls >Not supported</audio>
</div>
<div>
<input type="text" id="audioFile" size="60" />
</div>
<button id="playbutton" onclick="togglePlay();">Play</button>
See also
Send comments about this topic to Microsoft
Build date: 11/27/2012


