You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(media-keys): route macOS and Windows play/pause through the App's native helpers - #995
Refs #985. Follow-up to #986, which fixed the MPRIS arms on Linux.
handle_macos_media_events and handle_windows_media_events in src/runtime/startup.rs still called player.play() / player.pause() directly, so the playbar waited for librespot's Playing/Paused event, the same bug as MPRIS Play/Pause stops audio but spotatui keeps showing and reporting playing #985. Now Playing and the Windows media controls still update on that event for native playback.
The macOS Play, Pause, PlayPause and Stop keys and the Windows Play, Pause and Stop controls now go through App::pause_native_playback() / App::resume_native_playback(), like the TUI key and the MPRIS arms.
Both handlers decide whether the local player takes a key under the same lock that acts, so a player that recovery removed in between can't be paused or resumed by a stale handle.
macOS PlayPause picks its direction from native_is_playing and falls back to shared_is_playing only while it is still None, as on Linux. The direction is now a pure function, play_key_resumes, and the Linux PlayPause arm uses it through press_local_play_key, with no change in behavior.
route_remote_spotify_macos_event now counts the local player as playing only while native_is_playing isn't Some(false) (local_player_is_playing, the expression from fix(mpris): route play/pause through the App's native helpers #986 with a name). Without it, the new PlayPause would resume locally after another device took over, because shared_is_playing can still say playing then. It pauses that device instead.
macOS Stop no longer calls set_native_playback_intent(false) itself; pause_native_playback() already does.
Windows keeps its routing as it was: the local player takes a key only when it is available and a track is loaded (native_track_info), otherwise the Spotify fallback. Only what happens on the local player changed. That routing doesn't have the stale-flag problem: when another device takes over, the Stopped event clears native_track_info together with native_is_playing, and the playback poll clears it too, so the key goes to the fallback and pauses that device.
cargo clippy with the macOS job's feature list: clean
cargo test media_key_tests: test result: ok. 8 passed; 0 failed
cargo run: the ⏯ key and Control Center's Now Playing play/pause pause and resume, and the playbar follows at once.
Windows:
Desktop workflow on windows-latest (compiles the root crate with windows-media): run 42553881516 passed
Not run on a Windows machine.
Additional notes
The new tests cover the decisions the handlers make (play_key_resumes, local_player_is_playing, press_local_play_key), not the handlers themselves, which run in the OS media loops. Windows has no new test: its routing decision is the same as before.
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
MPRIS commands, media keys, macOS Now Playing, and Windows media controls now follow the app’s play/pause handling.
Playback state is more reliably reflected when another Spotify device takes over or local playback resumes.
Windows controls fall back to Spotify playback when no local track is loaded.
Reviewing files that changed from the base of the PR and between 69330f5 and 2a676de.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
MPRIS, macOS, and Windows media-key handlers now use App playback methods for play, pause, and stop actions. Local-player selection and toggle behavior account for App playback state alongside librespot’s shared state. macOS and Windows handlers use Spotify fallback routing in specified cases.
App-aware playback state and routing src/runtime/startup.rs
Local-player selection and play/pause toggles use App playback state alongside librespot’s shared state. Tests cover stale shared state, state precedence, and toggle behavior.
MPRIS, macOS, and Windows play, pause, and stop handling uses App playback methods. macOS and Windows handlers use Spotify fallback routing in the described cases. The changelog names media keys, macOS Now Playing, and Windows media controls.
LargeModGames/spotatui#986: Routes Linux MPRIS playback actions through App playback helpers. This PR uses the same helpers for macOS and Windows media actions.
LargeModGames/spotatui#954: Adds party-relay checks to macOS and Windows media-key handlers. This PR changes the local-player action in those handlers.
Merge Risk: Minimal · previous review 69330
This change makes macOS and Windows media keys update the playbar immediately by using the app's own playback helpers. No actionable merge-blocking risk was identified in the supplied material.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title uses the permitted fix(media-keys): prefix and clearly describes routing macOS and Windows play/pause actions through App helpers.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Simplify code
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between e1c6c45 and 69330f5.
Files selected for processing: 1
CHANGELOG.md
Files skipped from review as they are similar to previous changes: 1
CHANGELOG.md
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
Radhik-Amp
changed the title
Fix/media keys native pause macos windows
fix(media-keys): route macOS and Windows play/pause through the App's native helpers
Nov 9, 2026
The reason will be displayed to describe this comment to others. Learn more.
The comments at startup.rs:1499 and :1775 say Now Playing and SMTC follow at once, but for native playback they still only update on librespot's Playing/Paused event. Can you say "the playbar" there instead?
Thanks, I was mistaken. I changed both comments in startup.rs to say "the playbar" , and also fixed some wording for the helper's comments as well. I also updated the changelog and the PR description.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for picking this up after #986. I read the macOS and Windows handlers against main and the logic holds: the routing order is unchanged, the play/pause decision now happens under the lock that acts, and windows-media pulls in streaming, so resume_native_playback / pause_native_playback exist wherever the Windows handler compiles. player_opt and is_native_loaded are still used by SetPosition, so nothing goes unused there.
Notes, none blocking:
No PR leg compiles target_os = "windows" (the desktop.yml Windows job runs on main only), and a cross-check from macOS stops at ring's C build, so the Windows half is read, not compiled. If someone with a Windows box can run cargo clippy with cd.yml's Windows features before the merge, that closes it.
One behavior change worth a line in the description: on macOS, Play or PlayPause with a local player but nothing loaded used to call player.play() on an empty player and do nothing. It now goes through resume_native_playback, which dispatches StartPlayback(None, None, None) and resumes the last playback, like the TUI key. That looks like the right outcome.
Nit: after the early continue, the PlayPause | Play | Pause | Stop => {} arms in both handlers can't be reached. Matching only Next/Previous (and SetPosition on Windows) in an if let or a match with _ => {} would say that directly. Fine as is if you prefer the exhaustive match.
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
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.
Summary
Refs #985. Follow-up to #986, which fixed the MPRIS arms on Linux.
handle_macos_media_eventsandhandle_windows_media_eventsinsrc/runtime/startup.rsstill calledplayer.play()/player.pause()directly, so the playbar waited for librespot'sPlaying/Pausedevent, the same bug as MPRIS Play/Pause stops audio but spotatui keeps showing and reporting playing #985. Now Playing and the Windows media controls still update on that event for native playback.Play,Pause,PlayPauseandStopkeys and the WindowsPlay,PauseandStopcontrols now go throughApp::pause_native_playback()/App::resume_native_playback(), like the TUI key and the MPRIS arms.PlayPausepicks its direction fromnative_is_playingand falls back toshared_is_playingonly while it is stillNone, as on Linux. The direction is now a pure function,play_key_resumes, and the Linux PlayPause arm uses it throughpress_local_play_key, with no change in behavior.route_remote_spotify_macos_eventnow counts the local player as playing only whilenative_is_playingisn'tSome(false)(local_player_is_playing, the expression from fix(mpris): route play/pause through the App's native helpers #986 with a name). Without it, the new PlayPause would resume locally after another device took over, becauseshared_is_playingcan still say playing then. It pauses that device instead.Stopno longer callsset_native_playback_intent(false)itself;pause_native_playback()already does.native_track_info), otherwise the Spotify fallback. Only what happens on the local player changed. That routing doesn't have the stale-flag problem: when another device takes over, theStoppedevent clearsnative_track_infotogether withnative_is_playing, and the playback poll clears it too, so the key goes to the fallback and pauses that device.Testing
On
mainat2b6e9bd, Fedora 44:cargo fmt --all -- --check: cleancargo clippy --no-default-features --features telemetry,tui -- -D warningsandcargo clippy -- -D warnings: cleancargo clippywith theguileg's features (withoutaudio-viz, no PipeWire headers here): cleancargo test --no-default-features --features telemetry,tui:test result: ok. 1925 passed; 0 failedcargo test:test result: ok. 2458 passed; 0 failed; 8 ignoredruntime::startup::media_key_tests(streaming + MPRIS on Linux, or macOS media):a_stale_librespot_playing_flag_does_not_keep_the_media_keys_after_a_takeovera_toggle_reads_the_app_play_state_before_librespota_toggle_follows_librespot_until_the_app_knows_the_play_stateplay_and_pause_keys_ignore_the_play_statea_pause_key_then_a_toggle_pauses_then_resumes_the_last_playbackmacOS 27.0.1:
cargo clippywith the macOS job's feature list: cleancargo test media_key_tests:test result: ok. 8 passed; 0 failedcargo run: the ⏯ key and Control Center's Now Playing play/pause pause and resume, and the playbar follows at once.Windows:
windows-latest(compiles the root crate withwindows-media): run 42553881516 passedAdditional notes
The new tests cover the decisions the handlers make (
play_key_resumes,local_player_is_playing,press_local_play_key), not the handlers themselves, which run in the OS media loops. Windows has no new test: its routing decision is the same as before.Summary by CodeRabbit
Summary by CodeRabbit