Skip to content

Commit

Permalink
添加禁用字幕选项 (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
NieR4ever authored Oct 28, 2024
1 parent 6d065fb commit c16c91a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,19 @@ internal class ExoPlayerState @UiThread constructor(
}

override fun onTracksChanged(tracks: Tracks) {
subtitleTracks.candidates.value =
val newSubtitleTracks =
tracks.groups.asSequence()
.filter { it.type == C.TRACK_TYPE_TEXT }
.flatMapIndexed { groupIndex: Int, group: Tracks.Group ->
group.getSubtitleTracks()
}
.toList()
// 新的字幕轨道和原来不同时才会更改,同时将 current 设置为新字幕轨道列表的第一个
if (newSubtitleTracks != subtitleTracks.candidates.value) {
subtitleTracks.candidates.value = newSubtitleTracks
subtitleTracks.current.value = newSubtitleTracks.firstOrNull()
}

audioTracks.candidates.value =
tracks.groups.asSequence()
.filter { it.type == C.TRACK_TYPE_AUDIO }
Expand Down Expand Up @@ -385,6 +391,7 @@ internal class ExoPlayerState @UiThread constructor(
subtitleTracks.current.collect {
player.trackSelectionParameters = player.trackSelectionParameters.buildUpon().apply {
setPreferredTextLanguage(it?.internalId) // dummy value to trigger a select, we have custom selector
setTrackTypeDisabled(C.TRACK_TYPE_TEXT, it == null) // disable subtitle track
}.build()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun PlayerControllerDefaults.SubtitleSwitcher(
optionsProvider = { options },
renderValue = {
if (it == null) {
Text("自动")
Text("关闭")
} else {
Text(it.displayName, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ class VlcjVideoPlayerState(parentCoroutineContext: CoroutineContext) : PlayerSta
listOf(Label(null, it.description())),
)
}
subtitleTracks.current.value = subtitleTracks.candidates.value.firstOrNull()
}

private fun reloadAudioTracks() {
Expand Down

0 comments on commit c16c91a

Please sign in to comment.