docs/legacy-docs/guides/video-tracks.html
This documentation is for an outdated version of Video.js. See documentation for the current release.
Video Tracks are a function of HTML5 video for providing a selection of alternative video tracks to the user, so that they can change type of video they want to watch. Video.js makes video tracks work across all browsers. There are currently six types of tracks:
Right now adding video tracks in the HTML is unsupported. Video Tracks must be added programatically.
You must add video tracks programatically for the time being.
Video Track propertites and settings
One of the five track types listed above. Kind defaults to empty string if no kind is included, or an invalid kind is used.
The label for the track that will be show to the user, for example in a menu that list the different languages available for video tracks.
The two-letter code (valid BCP 47 language tag) for the language of the video track, for example "en" for English. A list of language codes is available here.
If this track should be playing or not. Trying to select more than one track will cause other tracks to be deselected.
When a new track is enabled (other than the main track) an event is fired on the VideoTrackList called change you can listen to that event and do something with it. Here's an example:
// get the current players VideoTrackList object
let tracks = player.videoTracks();
// listen to the change event
tracks.addEventListener('change', function() {
// get the currently selected track
let index = tracks.selectedIndex;
let track = tracks[index];
// print the currently selected track
console.log(track.label);
});
player.videoTracks() -> VideoTrackListThis is the main interface into the video tracks of the player. It returns an VideoTrackList which is an array like object that contains all the VideoTrack on the player.
player.videoTracks().addTrack(VideoTrack)Add an existing VideoTrack to the players internal list of VideoTracks.
player.videoTracks().removeTrack(VideoTrack)Remove a track from the VideoTrackList currently on the player. if no track exists this will do nothing.
player.videoTracks().selectedIndexThe current index for the selected track