Skip to main content
Version: 11.8.0

How to programmatically detect video track quality changes on iOS

This article describes how you can use the VideoTrack API, a sub-API of the MediaTrack API, to detect video track quality changes. Implementing this functionality is a common use-case for developers who want to build their own UI to visualize the video track quality that is currently active.

Usage

Listen for the ACTIVE_QUALITY_CHANGED event of a MediaTrack.

player.videoTracks.addEventListener(type: VideoTrackListEventTypes.ADD_TRACK, listener: { addTrackEvent in
guard let videoTrack = addTrackEvent.track as? VideoTrack else { return }
videoTrack.addEventListener(type: MediaTrackEventTypes.ACTIVE_QUALITY_CHANGED, listener: { qualityChangeEvent in
let quality = qualityChangeEvent.quality
var msg = "Quality changed: bandwidth = \(quality.bandwidth)"
if let videoQuality = quality as? VideoQuality {
msg.append(", width = \(videoQuality.width), height = \(videoQuality.height)")
}
print(msg)
})
})