decoderPriorityProvider

A callback interface for sorting and filtering decoders based on priority.

This callback is invoked when the player selects a decoder, providing the DecoderContext and a list of available MediaCodecInfo objects. The list is initially ordered by the default priority in which decoders will be attempted.

The callback should return a reordered or filtered list of MediaCodecInfo objects that determines the selection priority.

Example Usage

Prefer a specific decoder for main content video playback

The following example prioritizes a specific decoder for non-ad video playback:

val preferDecoderIfAvailable = DecoderPriorityProvider { decoderContext, decoders ->
if (!decoderContext.isAds && decoderContext.mediaType == MediaType.Video) {
// Prioritize a specific decoder
decoders.sortedByDescending { it.name.startsWith("OMX.google.") }
} else {
decoders
}
}

Prefer software decoders for ads playback

The following example prioritizes software decoders over hardware decoders for ad playback:

val preferSoftwareDecoderForAds = DecoderPriorityProvider { decoderContext, decoders ->
if (decoderContext.isAds) {
// Prioritize software decoders over hardware decoders
decoders.sortedByDescending { it.isSoftware }
} else {
decoders
}
}

Disable software fallback for video playback

The following example disables software decoders for non-ad video playback:

val disableSoftwareDecoders = DecoderPriorityProvider { decoderContext, decoders ->
if (!decoderContext.isAds && decoderContext.mediaType == MediaType.Video) {
// Do not use software decoders
decoders.filter { !it.isSoftware }
} else {
decoders
}
}