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

+13 -2
View File
@@ -32,7 +32,7 @@ struct MpvTrack: Identifiable, Hashable {
let type: String
let language: String
let title: String
let selected: Bool
var selected: Bool
/// The container marks it as the default choice.
var isDefault = false
/// The container marks it as forced: on-screen text only, by convention.
@@ -303,7 +303,18 @@ final class MpvPlayer {
/// A track, or none: `nil` turns subtitles off.
func select(type: String, track: MpvTrack?) {
setString(type == "audio" ? "aid" : "sid", track.map { String($0.id) } ?? "no")
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.
tracks = tracks.map { listed in
var listed = listed
if listed.type == type { listed.selected = listed.id == track?.id }
return listed
}
Task { [weak self] in
try? await Task.sleep(for: .milliseconds(300))
self?.refreshTracks()
}
}
/// Showing no picture while backgrounded keeps the audio playing: iOS