Track selection
To test this feature and view the example code, please see the Apple (FPS) SDK 5 Example Code Quick Start guide.
The CONNECT Player supports track selection for associated tracks in a stream; a track can be either a subtitle or an audio track.
Supported subtitle formats
OTVPlayer supports the following subtitle formats:
Closed Captions (CC)
WebVTT
ID3 SMPTE-TT/PNG
SRT
SMPTE and SRT formats require OTVPlayer.subtitleView to be set to a view into which the subtitles are rendered. For more information, see SRT subtitle tracks.
Prerequisites
A stream with multiple tracks is available for testing.
Example code
After enabling basic playback, start by setting up the view for tracks selection; this can be a simple UITableView with the list of tracks. The SelectorViewController will need to conform to UITableViewDelegate and UITableViewDataSource protocols.
To populate the table with the number of tracks available, the view controller class needs to conform to OTVTracksChangedListener protocol. The delegate method tracksChanged() is triggered when the tracks are loaded (based on their type) by OTVAVPlayer or when they change. Use this method as follows to load the tracks in the UITableView.
   func tracksChanged() {
       tracksView?.populate(from: otvPlayer)
   }
   func populate(from player: OTVAVPlayer) {
     selectableTracks[OTVTrackType.audio.rawValue] = player.tracks(type: .audio)
     //nil element added to add an option to disable subtitles
     var subtitleTracks = [OTVTrackInfo?]()
     subtitleTracks.append(nil)
     subtitleTracks.append(contentsOf: player.tracks(type: .subtitle))
     selectableTracks[OTVTrackType.subtitle.rawValue] = subtitleTracks
     selectedTrackIndices[OTVTrackType.audio.rawValue] = player.selectedTrack(type: .audio)
     selectedTrackIndices[OTVTrackType.subtitle.rawValue] = player.selectedTrack(type: .subtitle)
     listTableView?.reloadData()
   }
In the UITableView  delegate method, tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath), perform the respective visual selection of tracks and select the player tracks as follows.
 _ = otvPlayer.selectTrack(type: type, index: index)
At least one audio track has to be selected; selecting subtitle tracks is optional.