fix(android,ios): the track tick moves when a track is chosen, and no file inherits another's languages

Choosing an audio or subtitle track read the track list back before mpv
had made the switch, so the tick stayed on the old track until the next
poll. The tick now moves on the choice, and the list is read again
300 ms later to confirm it.

On Android, `load` set `alang` and `slang` only when they were not
empty. mpv keeps both across `loadfile`, so a file with no language
preference took the previous file's. Both are now set on every load.
This closes the last open item of B41.
This commit is contained in:
nvrl committed 2026-10-31 03:26:39 +01:00
1 parent 973a8f2749
commit 3fe4900337
4 files changed
+49 -15

No files matched your search

+5 -2
View File
@@ -323,8 +323,11 @@ class Player {
// needs no window, and a load that cannot get one plays audio anyway —
// waiting for a surface here is what made background playback fail after
// a five-second stall.
if (!audio.empty()) set_string("alang", audio);
if (!subtitle.empty()) set_string("slang", subtitle);
//
// Set even when empty: mpv keeps both across `loadfile`, so a file
// with no language preference used to inherit the last one's.
set_string("alang", audio);
set_string("slang", subtitle);
set_string("sid", subtitles ? "auto" : "no");
pending_start_.store(std::max(0.0, start));
// Retire the outgoing file's position, duration and end flag *before*
@@ -322,7 +322,17 @@ class NativeMpvHost private constructor(private val nativeHandle: Long) : Libmpv
fun selectTrack(track: MpvTrack?) {
val audio = track?.type == "audio"
withOpenHandle { nativeSelectTrack(it, audio, track?.id ?: -1) }
refreshTracks()
// mpv makes the switch on its own thread and lists it a moment later,
// so a track list read back now still ticks the old track. The tick
// moves here, and a read shortly after confirms it.
val type = if (audio) "audio" else "sub"
mutableTracks.value = mutableTracks.value.map {
if (it.type == type) it.copy(selected = it.id == track?.id) else it
}
scope.launch(Dispatchers.Default) {
delay(TRACK_SETTLE_MS)
refreshTracks()
}
}
/**
@@ -558,6 +568,9 @@ class NativeMpvHost private constructor(private val nativeHandle: Long) : Libmpv
private const val CACHED_UNTIL = 13
private const val LOADED = 14
/** How long after a track switch mpv's track list is read again. */
private const val TRACK_SETTLE_MS = 300L
init {
System.loadLibrary("pstr_android")
System.loadLibrary("pstr_mpv")