diff --git a/app/src/main/java/com/github/damontecres/wholphin/ui/playback/PlaybackViewModel.kt b/app/src/main/java/com/github/damontecres/wholphin/ui/playback/PlaybackViewModel.kt index 90dd6980..b1d22fa6 100644 --- a/app/src/main/java/com/github/damontecres/wholphin/ui/playback/PlaybackViewModel.kt +++ b/app/src/main/java/com/github/damontecres/wholphin/ui/playback/PlaybackViewModel.kt @@ -80,7 +80,6 @@ import org.jellyfin.sdk.model.api.BaseItemKind import org.jellyfin.sdk.model.api.DeviceProfile import org.jellyfin.sdk.model.api.MediaSegmentDto import org.jellyfin.sdk.model.api.MediaSegmentType -import org.jellyfin.sdk.model.api.MediaSourceInfo import org.jellyfin.sdk.model.api.MediaStreamType import org.jellyfin.sdk.model.api.PlayMethod import org.jellyfin.sdk.model.api.PlaybackInfoDto @@ -560,7 +559,7 @@ class PlaybackViewModel if (tracks.groups.isNotEmpty()) { applyTrackSelections( player, - source, + source.supportsDirectPlay, audioIndex, subtitleIndex, externalSubtitleCount, @@ -1026,17 +1025,24 @@ suspend fun onMain(block: suspend CoroutineScope.() -> T) = withContext(Disp @OptIn(UnstableApi::class) private fun applyTrackSelections( player: Player, - source: MediaSourceInfo, + supportsDirectPlay: Boolean, audioIndex: Int?, subtitleIndex: Int?, externalSubtitleCount: Int, subtitleIsExternal: Boolean, ) { - if (source.supportsDirectPlay) { - if (subtitleIndex != null && subtitleIndex >= 0) { - val indexToFind = - subtitleIndex + if (subtitleIsExternal) 0 else (if (externalSubtitleCount > 0) -1 else 1) - val chosenTrack = + if (subtitleIndex != null && subtitleIndex >= 0 && (subtitleIsExternal || supportsDirectPlay)) { + val chosenTrack = + if (subtitleIsExternal) { + player.currentTracks.groups.firstOrNull { group -> + group.type == C.TRACK_TYPE_TEXT && group.isSupported && + (0.. group.type == C.TRACK_TYPE_TEXT && group.isSupported && (0.. - group.type == C.TRACK_TYPE_AUDIO && group.isSupported && - (0.. + group.type == C.TRACK_TYPE_AUDIO && group.isSupported && + (0..