fix: route audio-only playback through afplay on macOS to avoid mpv/CoreAudio issue - #5205
Open
Annincikee wants to merge 2 commits into
Open
fix: route audio-only playback through afplay on macOS to avoid mpv/CoreAudio issue#5205Annincikee wants to merge 2 commits into
Annincikee wants to merge 2 commits into
Conversation
On macOS, route audio-only SoundOrVideoTags through the system's built-in afplay binary rather than mpv/MpvManager. Video playback is unaffected and still goes through mpv, since afplay only handles audio. afplay doesn't understand "--" as an options/filename separator (mpv and mplayer do), so SimpleProcessPlayer gained a supports_arg_separator flag to opt out of it per-player.
fix: route audio-only playback through afplay on macOS to avoid mpv/CoreAudio issue
Member
|
Bypassing mpv is not the right approach - pretty sure it doesn't support all formats (e.g. opus). We'll look into the issue once 26.08 is out. |
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.
Linked issue
Fixes #5157 for me locally (see verification below), but this is a
workaround, not a diagnosed root-cause fix in mpv/CoreAudio — see "Risk /
compatibility" for what that means, and I'd welcome maintainer input on
whether this is the right approach vs. something more surgical in mpv
itself (e.g. a newer bundled mpv, or an mpv.conf-level fix for the
channel-mapping issue below).
Summary / motivation
On macOS, mpv/
MpvManageris used for both audio and video playback. Onmy own Mac (macOS 27 beta, Anki 26.05), audio-only card playback was
cutting off partway through — the same symptom reported in #5157. The
unified log showed entries like this around each cutoff:
Caveat: I have not root-caused this inside mpv/CoreAudio itself — I
don't know why the channel mapping is failing, only that avoiding mpv's
CoreAudio output path for audio-only playback makes the cutoff go away on
my machine (see "How to test").
Since the overwhelming majority of
[sound:...]tags are audio-only, thisPR routes audio-only
SoundOrVideoTags through the system's built-inafplaybinary on macOS instead of mpv/MpvManager, avoiding mpv'sCoreAudio output path entirely for that case. Video playback is
unaffected and still goes through mpv, since afplay only handles audio.
Implementation notes
SimpleAfplayPlayeris a newSimpleProcessPlayer/SoundPlayerthatshells out to
/usr/bin/afplay, ranked aboveMpvManagerso it'schosen for audio tags; video tags still fall through to mpv since
SimpleAfplayPlayer.rank_for_tagreturnsNonefor them.afplaydoesn't accept--as an options/filename separator (unlikempv/mplayer), so
SimpleProcessPlayergained asupports_arg_separatorflag that
SimpleAfplayPlayeropts out of; mpv/mplayer/Windows/Linuxbehavior is unchanged (flag defaults to
True).How to test
Checklist (minimum)
"Risk" below for why, and happy to add one if maintainers want a
particular shape) — existing
qt/tests/test_sound.pycoverage(mpv packaging/playback) still passes unmodified.
What I actually verified
patch locally, packaged it into a DMG via the normal Briefcase
installer path, installed it on my own Mac, and confirmed audio-only
cards now play to completion — the cutoff is gone for me.
just buildandRELEASE=1 ./ninja pylib qtsucceed.ruff check/mypyclean onqt/aqt/sound.py.check:pytest(pylib + qt): 83/84 pass; the one failure(
test_compile_fails_loudly) is a pre-existing test that hits a livenetwork download and is unrelated to this change.
stringson the packagedaqt/sound.pycthat thebundled build contains the new
SimpleAfplayPlayer/afplay code path.What I did NOT verify
other [macOS 27] Audio playback stops before completion in Anki 26.05 #5157 reporters on whether this resolves it for them too.
channel layouts.
afplay's format coverage (CoreAudio-backed) vs. mpv's for everyextension in
AUDIO_EXTENSIONS(e.g.ogg/opus/spx) — notverified across all of them.
Risk / compatibility / migration
mpv/mplayer through
SimpleProcessPlayerunchanged.afplayhas a narrower feature set than mpv (no seek/pause API iswired up for it, since
Player.seek_relative/toggle_pauseareoptional no-ops by default) — audio-only cards lose in-player
seek/pause that mpv provided. This is a real functional regression,
not just a routing change, and the main thing I'd want maintainer
opinion on before this is mergeable as-is.
afplay's format support may not exactly match mpv's for everyextension in
AUDIO_EXTENSIONS; unverified.UI evidence
N/A — backend audio-playback routing change, no UI change.
Scope