Repository navigation
Fix audio track selection: manual picks first, automatic correction second - #1003
Merged
Riteshp2001 merged 3 commits intoNov 19, 2026
Merged
Conversation
…econd Decision order, applied identically on the foreground and detached paths: 1. When mpv.conf owns alang, the app does not intervene at all: no manual restore, no automatic correction, and no manual record is written. 2. A saved manual selection decides the load. It is applied inside the playback-state restore (before the position restore completes and before any automatic step), on every load including loads that carry a starting position, and it covers both a picked track and audio turned off by hand. External audio tracks are re-added first, because a manual pick can point at one of them. 3. With no manual record, mpv picks by preferred language (alang) as before. 4. The automatic correction (TrackSelector) only ever adjusts step 3's result, and never runs when step 2 decided: it keeps mpv's track when it is a clean track (no commentary/description markers, plural forms included) in any preferred language; otherwise it chooses among clean tracks by preference order with the file default track winning ties; otherwise it falls back to a clean track so a commentary track or a missing selection is not left in place. What was wrong and how this fixes it: - The old restore only ran with no position override, only for aid > 0, and conflated "audio off" (-1) with "no record". Manual selections are now stored separately (hasManualAudioSelection + manualAudioId, where 0 is manual off and -1 is no record), so all three states are distinct. - TrackSelector could override a restored pick with its own preference match, and its keep/re-pick rules disagreed with the restore. It now skips the audio step entirely when the restore decided, and its correction follows the single order above. - Every save stored whatever track was playing as the file's selection. Now only an explicit pick (PlayerViewModel.selectAudioTrack) creates a manual record, via ManualAudioSelectionTracker binding the exact track id; automatic changes (mpv's choice, the correction, quality-change pairing) are never persisted as manual, and a save without a pick carries the stored record over untouched. Both save sites (PlayerActivity, MediaPlaybackService) use the same rule. - A saved id that is unusable for a load (file replaced, id now belongs to another track type) is "not applicable this time", not "record void": validation reuses the track list TrackSelector already reads, the automatic rules decide that open, and the record stays stored. - External audio tracks were not persisted at all. They are now stored like external subtitles (externalAudio), tracked per load generation in PlayerViewModel (not cleared by title, which repeats across files), and re-added unselected before the manual restore validates. - Detached loads driven by MediaPlaybackService had no restore path at all. The service now runs the same sequence per load generation while it owns playback: re-add external audio, apply the manual selection, then the automatic correction. - A yt-dlp audio pick reloads the item and renumbers its tracks, so the pick is recorded as reload-pending and resolved at restore time to the track the reload selected. Database 31 -> 34 (34 stays above the two reverted builds' 32/33): 31 -> 34 adds the three columns with "no manual record" defaults, so pre-fix rows are decided by the automatic rules, per the migration policy that old aid values are not manual picks. 32 -> 34 clears the interim build's flags (that build marked every row manual) instead of carrying them over. 33 -> 34 carries the reverted build's flagged picks from aid into manualAudioId. Room schema JSON is generated at build time, as in the previous audio-fix attempts.
applySavedAudioSelection validated the saved track id against the whole track list. mpv track ids are per type - video, audio and subtitles each number from 1 - and the video track comes first in the list, so a saved aid of 1 matched the video track, failed the type check, and the manual record was reported "not usable" on every load. The automatic fallback then decided instead - or, when the gate was closed by an in-process mark, nothing decided and the open stayed silent. Validate inside the audio tracks only: the first track that is both an audio track and carries the saved id. No new reads: the validation uses the track list this step already fetched.
The gate after the foreground restore treated any in-process manual-pick mark for the file as "audio already decided". Marks live for the whole process and are never cleared, so a pick made in an earlier open of the same file suppressed the automatic correction in every later open - even when that open's restore could not apply the saved record. Both paths then decided nothing and the open could stay silent. A mark now records the load generation in which the pick was made, and the gate only counts a mark from the load it is deciding for. That keeps the case the mark term exists for - a pick made during this load, while its restore and subtitle autoload were still running, which the correction must not override - while a pick from an earlier load no longer closes the gate. Picks still carry across loads through the persisted record and the restore, unchanged; the save path reads the marked track id exactly as before.
|
@fzs209 is attempting to deploy a commit to the riteshp2001's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1001
Problem
A hand-picked audio track was not treated as a user choice. The restored track was applied on the next open, but the automatic language-based correction then ran anyway and overrode it within a fraction of a second. A selection the app itself had made automatically was also saved with the same weight as a manual pick, and restores were skipped entirely for opens that carried a start position.
Fix — decision order, applied identically on the foreground and detached (background service) paths
alang, the app does not intervene at all: no manual restore, no automatic correction, and no manual record is written.Implementation
Testing
These are the same three commits that run on my fork's
fongmi-fixesbranch, cherry-picked onto current master (bd4ac09) with no conflicts. On the fork build I verified on a real device: manual picks restored in-process and in fresh processes, for embedded tracks and for external audio files (including an external track landing behind seven embedded ones), and the negative case where the saved external file is missing — playback continued on the core's own pick and the record was kept. A CI build of this exact branch is running here: https://github.com/fzs209/mpvRx/actions/runs/44548906669Disclosure: the fix and this text were produced with AI assistance; all testing described above was performed by me personally on the real device.