Skip to main content
Version: 11.7.0

How to programmatically select a video track quality on iOS

This article describes how you can use the VideoTrack API, a sub-API of the MediaTrack API, to select a video track quality. If you select a specific quality, you overrule the ABR algorithm.

Implementing this functionality is a common use-case for developers who want to build their own UI to toggle a specific video quality.

Usage for HESP streams

For HESP streams, set the targetQualities of a MediaTrack.

let videoTrack = player.videoTracks[0]
videoTrack.targetQualities = [videoTrack.qualities[indexOfRequestedVideoTrackQuality]]
// or
videoTrack.targetQualities = [videoTrack.qualities[0], videoTrack.qualities[1]]

Usage for HLS streams

For HLS streams, the iOS SDK leverages the ABR API. The underlying AVFoundation stack, which THEOplayer has to use, brings along the technical limitation that you cannot select a specific video quality. Instead, you can set a maximum resolution or bitrate.

// set preferred peak bitrate
self.theoplayer.abr.preferredPeakBitRate = 200000

// self.theoplayer.abr.preferredPeakBitRate = nil // removes any bitrate limitation

// preferredMaximumResolution supported starting from iOS 11 and above
// self.theoplayer.abr.preferredMaximumResolution = CGSize(width: 1280, height: 720)
// self.theoplayer.abr.preferredMaximumResolution = CGSize.zero // removes any resolution limitation