Last active
December 29, 2021 21:45
-
-
Save prateek54/b4c8e7b56fc47f4500af62211b7e1050 to your computer and use it in GitHub Desktop.
Kotlin Extension Function to Generate Quality List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun DefaultTrackSelector.generateQualityList(): ArrayList<Pair<String, TrackSelectionOverrides.Builder>> { | |
//Render Track -> TRACK GROUPS (Track Array)(Video,Audio,Text)->Track | |
val trackOverrideList = ArrayList<Pair<String, TrackSelectionOverrides.Builder>>() | |
val renderTrack = this.currentMappedTrackInfo | |
val renderCount = renderTrack?.rendererCount ?: 0 | |
for (rendererIndex in 0 until renderCount) { | |
if (isSupportedFormat(renderTrack, rendererIndex)) { | |
val trackGroupType = renderTrack?.getRendererType(rendererIndex) | |
val trackGroups = renderTrack?.getTrackGroups(rendererIndex) | |
val trackGroupsCount = trackGroups?.length!! | |
if (trackGroupType == C.TRACK_TYPE_VIDEO) { | |
for (groupIndex in 0 until trackGroupsCount) { | |
val videoQualityTrackCount = trackGroups[groupIndex].length | |
for (trackIndex in 0 until videoQualityTrackCount) { | |
val isTrackSupported = renderTrack.getTrackSupport( | |
rendererIndex, | |
groupIndex, | |
trackIndex | |
) == C.FORMAT_HANDLED | |
if (isTrackSupported) { | |
val track = trackGroups[groupIndex] | |
val trackName = | |
"${track.getFormat(trackIndex).width} x ${track.getFormat(trackIndex).height}" | |
val trackBuilder = | |
TrackSelectionOverrides.Builder() | |
.clearOverridesOfType(C.TRACK_TYPE_VIDEO) | |
.addOverride(TrackSelectionOverrides.TrackSelectionOverride(track, | |
listOf(trackIndex))) | |
trackOverrideList.add(Pair(trackName, trackBuilder)) | |
} | |
} | |
} | |
} | |
} | |
} | |
return trackOverrideList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment