mirror of
https://github.com/jellyfin/jellyfin-androidtv.git
synced 2024-11-23 13:59:55 +00:00
Use relative index matching for subtitle selection
This commit is contained in:
parent
9732b3a232
commit
2ba2b70b85
@ -74,7 +74,8 @@ fun PlaybackController.setSubtitleIndex(index: Int, force: Boolean = false) {
|
|||||||
mCurrentOptions.subtitleStreamIndex = index
|
mCurrentOptions.subtitleStreamIndex = index
|
||||||
play(mCurrentPosition, index)
|
play(mCurrentPosition, index)
|
||||||
} else {
|
} else {
|
||||||
val stream = currentMediaSource.mediaStreams?.first { it.type == MediaStreamType.SUBTITLE && it.index == index }
|
val mediaSource = currentMediaSource
|
||||||
|
val stream = mediaSource.mediaStreams?.first { it.type == MediaStreamType.SUBTITLE && it.index == index }
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
Timber.w("Failed to find correct media stream")
|
Timber.w("Failed to find correct media stream")
|
||||||
return setSubtitleIndex(-1)
|
return setSubtitleIndex(-1)
|
||||||
@ -102,7 +103,22 @@ fun PlaybackController.setSubtitleIndex(index: Int, force: Boolean = false) {
|
|||||||
group.length == 1 && group.getTrackFormat(0).id?.endsWith(":JF_EXTERNAL:$index") == true
|
group.length == 1 && group.getTrackFormat(0).id?.endsWith(":JF_EXTERNAL:$index") == true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mVideoManager.mExoPlayer.currentTracks.groups.getOrNull(stream.index)
|
// The server does not send a reliable index in all cases, so calculate it manually
|
||||||
|
val localIndex = mediaSource.mediaStreams.orEmpty()
|
||||||
|
.filter { it.type == MediaStreamType.SUBTITLE }
|
||||||
|
.filter { it.deliveryMethod == SubtitleDeliveryMethod.EMBED || it.deliveryMethod == SubtitleDeliveryMethod.HLS }
|
||||||
|
.indexOf(stream)
|
||||||
|
.takeIf { index -> index != -1 }
|
||||||
|
|
||||||
|
if (localIndex == null) {
|
||||||
|
Timber.w("Failed to find local subtitle index")
|
||||||
|
return setSubtitleIndex(-1)
|
||||||
|
}
|
||||||
|
|
||||||
|
mVideoManager.mExoPlayer.currentTracks.groups
|
||||||
|
.filter { it.type == C.TRACK_TYPE_TEXT }
|
||||||
|
.filterNot { it.length == 1 && it.getTrackFormat(0).id?.endsWith(":JF_EXTERNAL:$index") == true }
|
||||||
|
.getOrNull(localIndex)
|
||||||
}?.mediaTrackGroup
|
}?.mediaTrackGroup
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user