fix(mpv): re-emit tracksReady after FILE_LOADED to win the disable race

Initial subtitle selection now comes from JS on tracksReady; FILE_LOADED still
disables subtitles, which could wipe a JS selection that landed first on
embedded-only files (no later track-list change to re-fire). Re-emitting
tracksReady after the disable guarantees the idempotent JS re-apply always runs
last. Also guards the iOS track-id read against failure, matching Android.
This commit is contained in:
Gauvain
2026-07-06 23:48:22 +02:00
parent 14ea18e0d2
commit 80602ecd23
2 changed files with 20 additions and 4 deletions

View File

@@ -851,6 +851,13 @@ class MPVLayerRenderer(private val context: Context) : MPVLib.EventObserver {
initialAudioId?.let { if (it > 0) setAudioTrack(it) }
initialSubtitleId?.let { setSubtitleTrack(it) } ?: disableSubtitles()
// The disable above can race a JS-side identity selection that
// landed before FILE_LOADED (JS no longer passes an initial sid).
// Re-emit tracksReady so the idempotent JS re-apply always runs
// after it — for embedded-only files this is the only
// post-FILE_LOADED fire.
mainHandler.post { delegate?.onTracksReady() }
if (!isReadyToSeek) {
isReadyToSeek = true
mainHandler.post { delegate?.onReadyToSeek() }