From 19b9471a5743cf8ab729e935123cf4a3d1e6eba5 Mon Sep 17 00:00:00 2001 From: Nier4ever <20170127nwl@gmail.com> Date: Mon, 4 Nov 2024 10:03:56 +0800 Subject: [PATCH] fix subtitle --- .../src/desktopMain/kotlin/ui/VideoPlayer.desktop.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/shared/video-player/src/desktopMain/kotlin/ui/VideoPlayer.desktop.kt b/app/shared/video-player/src/desktopMain/kotlin/ui/VideoPlayer.desktop.kt index cc64e418d0..2ae901d8fc 100644 --- a/app/shared/video-player/src/desktopMain/kotlin/ui/VideoPlayer.desktop.kt +++ b/app/shared/video-player/src/desktopMain/kotlin/ui/VideoPlayer.desktop.kt @@ -441,7 +441,7 @@ class VlcjVideoPlayerState(parentCoroutineContext: CoroutineContext) : PlayerSta } private fun reloadSubtitleTracks() { - subtitleTracks.candidates.value = player.subpictures().trackDescriptions() + val newSubtitleTracks = player.subpictures().trackDescriptions() .filterNot { it.id() == -1 } // "Disable" .map { SubtitleTrack( @@ -451,7 +451,11 @@ class VlcjVideoPlayerState(parentCoroutineContext: CoroutineContext) : PlayerSta listOf(Label(null, it.description())), ) } - subtitleTracks.current.value = subtitleTracks.candidates.value.firstOrNull() + // 新的字幕轨道和原来不同时才会更改,同时将 current 设置为新字幕轨道列表的第一个 + if (subtitleTracks.candidates.value != newSubtitleTracks) { + subtitleTracks.candidates.value = newSubtitleTracks + subtitleTracks.current.value = newSubtitleTracks.firstOrNull() + } } private fun reloadAudioTracks() {