Skip to main content
Version: 11.7.0

How to start with a specific quality on Android

This article describes how you can start playback with a specific quality. Developers typically want their HLS or MPEG-DASH stream to start with a specific rendition of the manifest to speed up the time-to-first-frame, to serve a better quality to the customer, or to serve a different quality on different platforms.

Usage

When the ADDTRACK event is dispatched, THEOplayer has not started buffering yet, so you can still adjust the targetQuality. You reset the ABR selection by setting targetQuality to null.

val progressListener = object : EventListener<ProgressEvent> {
override fun handleEvent(event: ProgressEvent) {
val buffered = player.buffered
// switch to normal ABR when THEOplayer buffered beyond 10 seconds
if (buffered.length() > 0 && buffered.getEnd(buffered.length() - 1) > 10) {
player.videoTracks.getItem(0).targetQuality = null
player.removeEventListener(PlayerEventTypes.PROGRESS, this)
}
}
}

player.videoTracks.addEventListener(VideoTrackListEventTypes.ADDTRACK) {
val videoTrack = player.videoTracks.getItem(0)
// start with a specific quality
videoTrack.targetQuality = videoTrack.qualities.getItem(0)
player.addEventListener(PlayerEventTypes.PROGRESS, progressListener)
}