addtrack | onaddtrack event
Occurs when a track is added to the track list on a video object.
![]() ![]() |
Syntax
| Event Property | object.onaddtrack = handler; |
|---|---|
| addEventListener Method | object.addEventListener("addtrack", handler, useCapture) |
Event information
| Synchronous | No |
|---|---|
| Bubbles | No |
| Cancelable | No |
Event handler parameters
- handler [in]
-
Type: Function
Handler function to process the addtrack event.
Standards information
Remarks
The addtrack event fires when a text track or audio track are added to a video object
The following example adds an event listener for the addtrack event to display the language of each audio track associated with the video object.
Examples
<script type="text/javascript">
// Wait for all DOM content to load
document.addEventListener("DOMContentLoaded", function () {
// Get video element, and add an addtrack event handler
var oVideo = document.getElementById("video1");
oVideo.audioTracks.addEventListener("addtrack", addHandler, false);
}, false);
// Print the language that was just added
function addHandler(evt) {
document.getElementById("display").innerHTML += evt.track.language + " language added" + "<br/>";
}
</script>
</head>
<body>
<video id="video1" controls >
<!-- Video file with multiple audio tracks -->
<source src="multi-lang-movie.mp4" >
"HTML5 video is not supported on this browser"
</video>
<br />
<!-- Display area for languages -->
<div id="display"></div>
</body>
</html>
See also
- TextTrackList
- AudioTrack
- AudioTrackList
- VideoTrack
- VideoTrackList
- Make your videos accessible with Timed Text Tracks
- video
Show:

