Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. VideoTrack

VideoTrack

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

TheVideoTrack interface represents a single video track from a<video> element.

The most common use for accessing aVideoTrack object is to toggle itsselected property in order to make it the active video track for its<video> element.

Instance properties

selected

A Boolean value which controls whether or not the video track is active. Only a single video track can be active at any given time, so setting this property totrue for one track while another track is active will make that other track inactive.

idRead only

A string which uniquely identifies the track within the media. This ID can be used to locate a specific track within a video track list by callingVideoTrackList.getTrackById(). The ID can also be used as the fragment part of the URL if the media supports seeking by media fragment per theMedia Fragments URI specification.

kindRead only

A string specifying the category into which the track falls. For example, the main video track would have akind of"main".

labelRead only

A string providing a human-readable label for the track. For example, a track whosekind is"sign" might have alabel of"A sign-language interpretation". This string is empty if no label is provided.

languageRead only

A string specifying the video track's primary language, or an empty string if unknown. The language is specified as aBCP 47 language tag such as"en-US" or"pt-BR".

sourceBufferRead only

TheSourceBuffer that created the track. Returns null if the track was not created by aSourceBuffer or theSourceBuffer has been removed from theMediaSource.sourceBuffers attribute of its parent media source.

Usage notes

To get aVideoTrack for a given media element, use the element'svideoTracks property, which returns aVideoTrackList object from which you can get the individual tracks contained in the media:

js
const el = document.querySelector("video");const tracks = el.videoTracks;

You can then access the media's individual tracks using either array syntax or functions such asforEach().

This first example gets the first video track on the media:

js
const firstTrack = tracks[0];

The next example scans through all of the media's video tracks, activating the first video track that is in the user's preferred language (taken from a variableuserLanguage).

js
for (const track of tracks) {  if (track.language === userLanguage) {    track.selected = true;    break;  }}

Thelanguage is specified as a validBCP 47 language tag, for example"en-US" for US English.

Specifications

Specification
HTML
# videotrack

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp