fix: Subtitle/audio mismatch under certain conditions and with multiple default tracks - #1044
Merged
PartyDonut merged 2 commits intoAug 9, 2026
Conversation
At playback start setSubtitleTrack/setAudioTrack ran before media_kit finished parsing the file's tracks (open() returns before the track-list observer fires), so the positional remap resolved to null and the selection was silently skipped. mpv then kept its own default pick, which is wrong when a file has multiple default tracks. Wait for the wanted embedded track to appear on the tracks stream before mapping. The wait only fires when the track is not yet present, is race-free, and is capped at 5s, so already-loaded and external cases are unchanged. Fixes DonutWare#1031
PartyDonut
reviewed
Aug 9, 2026
PartyDonut
requested changes
Aug 9, 2026
The onTimeout callback in _awaitTrack ran up to 5 seconds after the await suspended, and dereferenced _player with a bang. By then the player can be null (dispose() nulls it, and the audio-queue path swaps it), so the timeout path threw a TypeError instead of returning the current tracks — turning the graceful-degradation branch into the one that breaks track selection. Hoists _player into a local that flow-promotes to non-nullable, so both the stream subscription and the timeout callback capture a non-null instance and neither needs an assertion.
PartyDonut
approved these changes
Aug 9, 2026
PartyDonut
left a comment
Collaborator
There was a problem hiding this comment.
lgtm, thanks for the quick changes.
irican-f
pushed a commit
to irican-f/Fladder-Maktep
that referenced
this pull request
Aug 10, 2026
Brings in 142 upstream commits (60 substantive, ~82 Weblate) on top of maktep. Merge base was 796dd5a. Conflicts resolved (14 files): Generated (regenerated via build_runner, not hand-merged): account_model.freezed, library_filters_model.{freezed,g}, video_player_settings.g, user_provider.g, auto_router.gr lib/l10n/app_fr.arb Union of upstream Weblate French with maktep's jellybot keys; kept maktep's "Cine Maktep" branding; dropped a duplicated authLinkButtonToolTip that upstream now defines earlier in the file. lib/wrappers/players/lib_mpv.dart Both branches independently fixed the same bug (mpv populates track-list asynchronously, so a selection made right after loadVideo hits a still-empty list). Kept maktep's _waitForTrackList - it guards kIsWeb and uses skip() rather than getRange() so it cannot throw if the player is disposed mid-wait - and adopted upstream DonutWare#1044's index-aware bound (wait for audioTracks[index + 2], not merely "any internal track"), which is the part that actually fixes files with several default-flagged streams. lib/wrappers/media_control_wrapper.dart Upstream's try/finally around loadVideo plus maktep's isLiveStream arg. lib/screens/shared/default_title_bar.dart Took upstream's rewrite wholesale, re-applied maktep's two real deltas: isFullScreen tracking on the maximize button and the "Cine Maktep" fallback label. lib/screens/home_screen.dart Kept upstream's music-dashboard gating of the Library tab and maktep's jellybot / jellybotLiveTv destinations. Re-declared isMusicDashboardMode, which maktep had dropped from this file. lib/widgets/navigation_scaffold/components/side_navigation_bar.dart Upstream extracted the rail buttons into side_navigation_buttons.dart (-218 lines); maktep's actionButtonWidget customFab hook survived and was rebased onto ConsumerWidget (no more "widget." prefix). fladder_app_bar.dart, service_provider.dart, play_item_helpers.dart Import unions, plus upstream's isDesktop constructor param combined with maktep's !kIsWeb guard. Verified: flutter analyze clean; flutter test 148 passed, 1 skipped, 1 failed (test/widget_test.dart, the untouched Flutter boilerplate counter test - failing since Init repo, unrelated to this merge). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Pull Request Description
At playback start,
setSubtitleTrack/setAudioTrack(inLibMPV) ran beforemedia_kithad finished parsing the file's tracks —open()returns before the mpvtrack-listobserver fires. Both wrappers map the wanted Jellyfin stream to a player track by list position, so while the track list is still empty the lookup resolves tonulland the selection is silently skipped. mpv then keeps the track it auto-selected on load — its first default-flagged track — which is wrong whenever a file has multiple default tracks (e.g. Jellyfin's smart subtitle selection picks the 2nd default).This is exactly why the in-player UI showed the correct track while a different one actually played, and why re-selecting the same track fixed it (by then the track list had been parsed).
Fix
lib/wrappers/players/lib_mpv.dart: before mapping the wanted stream to a player track, wait for that track to appear onplayer.stream.tracks. The wait:play: true), only the track application waits, and only until mpv finishes parsing (tens of ms);firstWheresubscribes synchronously before any track-list observer callback can run;Applied to both subtitle and audio selection. The
libMDKwrapper has the same latent race but is intentionally left out of scope to keep the diff minimal.AI assistance
Root-cause investigation and the patch were done with Claude Code. The diagnosis — traced through the vendored DonutWare
media_kitfork to confirmopen()returns before track parsing and thatTracks.subtitledefaults to[auto, no]— the fix design, and on-device validation were human-reviewed and -owned.Issue Being Fixed
Resolves #1031 — when a file has multiple subtitle tracks marked as default, the UI selects the correct one but playback uses the first default track instead.
Screenshots / Recordings
Tested On
LibMPVcode path as Android; not separately re-tested but covered by the same fix.Checklist