Video audioTracks Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video

Description

The audioTracks property returns a AudioTrackList object, which represents the available audio tracks for the video.

Each available audio track is represented by an AudioTrack Object.

Return Value

Type Description
AudioTrackList Object Represents the available audio tracks for the video.
AudioTrack Object Represents an audio track.

AudioTrackList Object:

  • audioTracks.length - get the number of audio tracks available
  • audioTracks.getTrackById(id) - get AudioTrack object by id
  • audioTracks[index] - get AudioTrack object by index

The first available AudioTrack object is index 0

AudioTrack Object Properties:

  • id - get the id of the audio track
  • kind - get the type of the audio track ("alternative", "description", "main", "translation", "commentary", or "")?
  • label - get the label of the audio track
  • language - get the language of the audio track
  • enabled - get or set if the track is active (true|false)

The following code shows how to get the number of available audio tracks:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>/*from   ww  w.j av  a 2 s  . c o m*/

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myVideo").audioTracks.length;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials