mirror of
https://github.com/jellyfin/jellyfin-android.git
synced 2026-10-26 16:45:26 +00:00
Fix audio track selection if multiple renderers are used
When ExoPlayer has to use multiple different renderers, the order of mapped track groups returned by the player may not conform to the order of media streams in the media source. Unfortunately, ExoPlayer doesn't allow accessing the original TrackGroups that are kept in the MediaPeriod, thus we instead simply sort the available groups by the format id.
This commit is contained in:
1 parent
cf576b9345
commit
6547b727fe
1 file changed
+7
-4
@@ -70,9 +70,12 @@ class TrackSelectionHelper(
|
||||
|
||||
val player = viewModel.playerOrNull ?: return false
|
||||
val embeddedStreamIndex = mediaSource.getEmbeddedStreamIndex(audioStream)
|
||||
val audioGroup = player.currentTracks.groups.getOrNull(embeddedStreamIndex)?.mediaTrackGroup ?: return false
|
||||
val sortedTrackGroups = player.currentTracks.groups.sortedBy { group ->
|
||||
group.mediaTrackGroup.getFormat(0).id
|
||||
}
|
||||
val audioGroup = sortedTrackGroups.getOrNull(embeddedStreamIndex) ?: return false
|
||||
|
||||
return trackSelector.selectTrackByTypeAndGroup(C.TRACK_TYPE_AUDIO, audioGroup)
|
||||
return trackSelector.selectTrackByTypeAndGroup(C.TRACK_TYPE_AUDIO, audioGroup.mediaTrackGroup)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,9 +135,9 @@ class TrackSelectionHelper(
|
||||
SubtitleDeliveryMethod.EMBED -> {
|
||||
// For embedded subtitles, we can match by the index of this stream in all embedded streams.
|
||||
val embeddedStreamIndex = mediaSource.getEmbeddedStreamIndex(subtitleStream)
|
||||
val subtitleGroup = player.currentTracks.groups.getOrNull(embeddedStreamIndex)?.mediaTrackGroup ?: return false
|
||||
val subtitleGroup = player.currentTracks.groups.getOrNull(embeddedStreamIndex) ?: return false
|
||||
|
||||
return trackSelector.selectTrackByTypeAndGroup(C.TRACK_TYPE_TEXT, subtitleGroup)
|
||||
return trackSelector.selectTrackByTypeAndGroup(C.TRACK_TYPE_TEXT, subtitleGroup.mediaTrackGroup)
|
||||
}
|
||||
SubtitleDeliveryMethod.EXTERNAL -> {
|
||||
// For external subtitles, we can simply match the ID that we set when creating the player media source.
|
||||
|
||||
Reference in new issue
Block a user