The player's audioTracks and videoTracks attributes can be used to change the active audio or video track. Changing the video quality can now be done by setting the targetQuality property on a track’s qualities property.

Examples

All examples assume player is a THEOplayer instance.

Query the currently active video’s (if there’s only 1) resolution:

var vTracks = player.videoTracks,
    currentTrack,
    currentQuality;
for (var i = 0; i < vTracks.length; i++) {
    currentTrack = vTracks.item(i);
    if (currentTrack.enabled) {
        return currentTrack.qualities.activeQuality.resolution;
    }	
}

Change to the second audio track:

var aTracks = player.audioTracks;
aTracks.enable(aTracks.item(1));

Change to the video quality with ID 3, part of the first track:

var firstTrack = player.videoTracks.item(0);
firstTrack.qualities.targetQuality = firstTrack.qualities.getQualityWithID(3);

TrackList

Both audioTracks and videoTracks are TrackList objects. TrackList exposes the following attributes:

AttributeDescription
enable(track) Enables the track corresponding to the given track object
disable(track) Disables the track corresponding to the given track object
item(index) Returns the track object at the given index
getTrackByID(id)

Returns the track object with the given ID

length

Returns the number of tracks in this list

Each TrackList generates the following events:

EventDescription
addtrack { track: Track } The track track was added to the TrackList
enabledtrack { track: Track } The track track was enabled
disabledtrack { track: Track } The track track was disabled

Track

Track objects have certain identifying properties and contain a QualityList. They expose the following properties:

PropertyDescription
id Returns a number that uniquely identifies this track
enabled Returns a boolean indicating whether this track is enabled
qualities Returns a QualityList containing this track’s qualities
name Sets or returns this track’s name
language Returns the language code for this track
default Returns a boolean indicating whether this track is the default track for its kind

QualityList

QualityList objects contain the qualities associated with a specific track. For video tracks these represent the different bitrates the video is available in, ordered from low to high. Audio qualities that correspond directly to video qualities from a single video track are grouped in a single audio track. Qualities that correspond to alternatives to the default audio (for example, other languages or commentary tracks) are placed in separate tracks.

QualityLists expose the following attributes:

AttributeDescription
item(index) Returns the quality at the specified index
getQualityByID(id) Returns the quality with the specified ID, if it belongs to the track that contains this QualityList
length Returns the amount of qualities in this track
activeQuality Returns the currently active quality for this track, if there is any
targetQuality Sets or returns the target quality for this track. Setting it only works for QualityLists belonging to video tracks, on audio tracks it does nothing. Setting it to null on a video track switches that track to automatic quality switching. the Quality set as targetQuality must be enabled.

 

A QualityList also generates the following event:

EventDescription
activequalitychanged { quality: Quality } The active quality for this track was changed (the new Quality is included)
targetqualitychanged { quality: Quality } The target quality for this track was changed (the new Quality is included)

Quality

A quality is a representation of a piece of audio or video that can actually be played. As mentioned before the way Quality objects are organized into tracks depends on the structure of the stream.

A Quality object exposes the following properties:

PropertyDescription
bandwidth Returns the required bandwidth for this quality as defined by the manifest
averageBandwidth Returns the effective average bandwidth for this quality. This may not be known
codecs Returns a string containing the codecs for this quality
enabled Sets or returns if this quality is enabled for automatic selection by the Adaptive Bitrate Engine. The engine will select only qualities which have enabled set to true. At least one quality of the quality list must be enabled for playback to continue.
resolution Returns a {width, height} object with the resolution for this quality (only applies to video)
frameRate Returns the framerate for this quality. This will return null for qualities which have not been played
name Sets or returns this quality’s name (this can be provided by the stream manifest)
id Returns the unique identifier for this quality
uri Returns the uri where this quality’s source material can be found