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

@@ -508,6 +508,15 @@ final class MPVLayerRenderer {
} else {
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.
DispatchQueue.main.async { [weak self] in
guard let self else { return }
self.delegate?.renderer(self, didBecomeTracksReady: true)
}
if !isReadyToSeek {
isReadyToSeek = true
DispatchQueue.main.async { [weak self] in
@@ -759,8 +768,8 @@ final class MPVLayerRenderer {
trackType == "sub" else { continue }
var trackId: Int64 = 0
getProperty(handle: handle, name: "track-list/\(i)/id", format: MPV_FORMAT_INT64, value: &trackId)
guard getProperty(handle: handle, name: "track-list/\(i)/id", format: MPV_FORMAT_INT64, value: &trackId) >= 0 else { continue }
var track: [String: Any] = ["id": Int(trackId)]
if let title = getStringProperty(handle: handle, name: "track-list/\(i)/title") {
@@ -892,8 +901,8 @@ final class MPVLayerRenderer {
trackType == "audio" else { continue }
var trackId: Int64 = 0
getProperty(handle: handle, name: "track-list/\(i)/id", format: MPV_FORMAT_INT64, value: &trackId)
guard getProperty(handle: handle, name: "track-list/\(i)/id", format: MPV_FORMAT_INT64, value: &trackId) >= 0 else { continue }
var track: [String: Any] = ["id": Int(trackId)]
if let title = getStringProperty(handle: handle, name: "track-list/\(i)/title") {