mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-07-05 03:52:51 +01:00
addressing more PR comments
Signed-off-by: Lance Chant <13349722+lancechant@users.noreply.github.com>
This commit is contained in:
@@ -189,6 +189,16 @@ class ExoPlayerView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
|
||||
override fun onTracksChanged(tracks: Tracks) {
|
||||
rebuildTrackMaps(tracks)
|
||||
// currentSubtitleId is a hand-maintained cache (ExoPlayer has no
|
||||
// mpv-style "sid" property to read live), so re-derive it from the
|
||||
// actual selection on every track change. Without this, any path
|
||||
// that selects a track without going through setSubtitleTrack —
|
||||
// notably addSubtitleFile(select=true), which clears the text
|
||||
// override and lets the new SELECTION_FLAG_DEFAULT sub render —
|
||||
// leaves the cache stale and getCurrentSubtitleTrack() reporting
|
||||
// the old id. Run before applyInitialTrackSelections() so an
|
||||
// explicit initial selection still wins.
|
||||
syncCurrentSubtitleIdFromSelection(tracks)
|
||||
applyInitialTrackSelections()
|
||||
// A track change can re-initialize the codec under a different
|
||||
// name (e.g. adaptive switch from HEVC to AV1). Clear stale
|
||||
@@ -501,6 +511,20 @@ class ExoPlayerView(context: Context, appContext: AppContext) : ExpoView(context
|
||||
audioTrackList = audios
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror the player's actually-selected text track into [currentSubtitleId].
|
||||
* Must run after [rebuildTrackMaps] so the 1-based IDs in [subtitleTrackList]
|
||||
* are current for this [tracks] snapshot. Falls back to 0 (subs off) when no
|
||||
* text track is selected.
|
||||
*/
|
||||
private fun syncCurrentSubtitleIdFromSelection(tracks: Tracks) {
|
||||
val groups = tracks.groups
|
||||
val selected = subtitleTrackList.firstOrNull { entry ->
|
||||
groups[entry.trackGroupIndex].isTrackSelected(entry.trackIndex)
|
||||
}
|
||||
currentSubtitleId = selected?.id ?: 0
|
||||
}
|
||||
|
||||
private fun applyInitialTrackSelections() {
|
||||
val p = player ?: return
|
||||
val cfg = pendingConfig ?: return
|
||||
|
||||
Reference in New Issue
Block a user