Track Selection

The Player SDK for FPS supports track selection for associated tracks in a stream.

Prerequisites

  • A stream that has multiple tracks. A track can be either a subtitle or an audio track.

Procedure

Follow the steps in the Integration Guide if you need to understand the process for basic playback, and the setting up of the PlayerView and main.storyboard.

  1. After the setup for basic playback, start with setting up view for tracks selection. It can be a simple UITableView with the list of tracks. The SelectorViewController will need to conform to UITableViewDelegate and UITableViewDataSource protocols.

  2. 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 by OTVAVPlayer or when the tracks change. The tracks are loaded based on their type. 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()
    }
    
  3. 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 and selecting subtitle tracks is optional.

  4. Build and run on device/simulator to use the track selection feature.

Supported subtitle formats

OTVPlayer supports the following subtitle formats:

  • Closed Captions (CC)
  • WebVTT
  • ID3 SMPTE-TT/PNG
  • SRT

Both the SMPTE and SRT formats require OTVPlayer.subtitleView to be set to a view you wish the subtitles to be rendered into. For more information, see SRT subtitle tracks.