feat(macos): drive the system Now Playing session through mpv
macOS has no D-Bus/MPRIS: the audio engine is what the OS media UI talks to. mpv's Cocoa backend registers with MPRemoteCommandCenter and MPNowPlayingInfoCenter, so it already publishes the live ICY title and receives the media keys. Add a platform-neutral media session (mediasession.py) so the app keeps a single interface: MprisService on D-Bus platforms, NowPlayingSession on macOS. Map mpv's NEXT/PREV/PLAY/PLAYONLY/PAUSEONLY/STOP keys onto script-messages and read them back as client-message IPC events, so the hardware media keys and Control Center drive the TUI (station changes, play/pause/stop) instead of fighting it. --no-mpris (now also --no-media) disables the media keys too. macOS-only mpv options are gated on sys.platform so the Linux command line is unchanged; mpv aborts on unknown flags.
This commit is contained in:
1 parent
d83a9ef03d
commit
9c722c5f61
8 files changed
+415
-37
No files matched your search
@@ -34,8 +34,11 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
parser.add_argument("--volume", type=int, metavar="0-100", help="initial volume")
|
||||
parser.add_argument(
|
||||
"--no-mpris",
|
||||
"--no-media",
|
||||
dest="no_mpris",
|
||||
action="store_true",
|
||||
help="do not announce playback over MPRIS",
|
||||
help="do not publish to the desktop media session (MPRIS on Linux, "
|
||||
"Now Playing on macOS) and ignore the media keys",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--offline",
|
||||
@@ -51,7 +54,8 @@ def _build_parser() -> argparse.ArgumentParser:
|
||||
"--spectrum-source",
|
||||
choices=SOURCE_MODES,
|
||||
default="auto",
|
||||
help="spectrum audio source: auto (monitor→stream→sim), monitor, "
|
||||
help="spectrum audio source: auto (monitor→stream→sim), monitor "
|
||||
"(parec on Linux, an avfoundation loopback device on macOS), "
|
||||
"stream (muted second ffmpeg decode), or sim",
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -109,7 +113,7 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||
autoplay=args.autoplay,
|
||||
station_id=args.station,
|
||||
volume=args.volume,
|
||||
mpris=not args.no_mpris,
|
||||
media=not args.no_mpris,
|
||||
offline=args.offline,
|
||||
audio=not args.no_audio,
|
||||
spectrum_source=args.spectrum_source,
|
||||
|
||||
Reference in new issue
Block a user