Skip to main content

Track Selection

Track types

Each playback can have four types of tracks - AUDIO , VIDEO, CLOSED CAPTION and SUBTITILE. These different track types are denoted using MediaTrack.trackType.

public enum MediaTrackType {
/// Audio
case audio
/// Closed Caption
case closedCaption
/// Subtitle
case subtitle
/// Video
case video
}

List available Tracks

All the available tracks of each type of track can be obtained using the tracks(for:) API on the player. This API returns an Array of MediaTrack objects.

// get all video tracks
var availableVideoTracks = player.tracks(for: .video)

//get all audio tracks
var availableAudioTracks = player.tracks(for: .audio)

//get all closedCaption tracks
var availableClosedCaptionTracks = player.tracks(for: .closedCaption)

//get all subtitle tracks
var availableSubtitleTracks = player.tracks(for: .subtitle)

Get active Track

The currently active track in each type can be obtained from the Player using the selectedTrack(for:) API. This API returns the active track of any given a MediaTrack.

///get active subtitles of tracks
var activeSubtitleTrack = player.selectedTrack(for: .subtitle)

///get active audio
var activeAudioTrack = player.selectedTrack(for: .audio)

///get active video
var activeVideoTrack = player.selectedTrack(for: .video)

///get active closedCaption
var activeCCTrack = player.selectedTrack(for: .closedCaption)

Set a track

///From list of available tracks for `AUDIO` , `VIDEO`, `CLOSED CAPTION` and `SUBTITILE` , users can choose any track and select it using the selectTrack(for:) API.
player?.selectTrack(selectedTrack, for: .audio)
player?.selectTrack(selectedTrack, for: .video)
player?.selectTrack(selectedTrack, for: .closedCaption)
player?.selectTrack(selectedTrack, for: .subtitle)

///To unselect a track pass nil to the selectTrack(for:) API, it will unselect the track.
player?.selectTrack(nil, for: .audio)
player?.selectTrack(nil, for: .video)
player?.selectTrack(nil, for: .closedCaption)
player?.selectTrack(nil, for: .subtitle)