Repository navigation
feat(music): play to Sonos and other speakers through Music Assistant - #3078
Closed
JackDanger wants to merge 1 commit into
Closed
JackDanger wants to merge 1 commit into
JackDanger wants to merge 1 commit into
Conversation
Adds Music Assistant (https://music-assistant.io) as a way to play music on speakers around the house: Sonos, Chromecast, AirPlay speakers, and anything else it knows. It is an output only. The music still comes from the user's Plex library; Music Assistant is just told what to play and where. **Adding a server.** Settings > Add server gets a fourth card. The app looks for a Music Assistant server on the network (Bonjour, `_mass._tcp`) and lists what it finds; an address can also be typed in. Servers from 2.10 on need a sign-in, with the same username and password as its web interface, or a long-lived token. **Choosing where to play.** Album and artist screens, the mini player and Now Playing get a speaker button whenever there is somewhere other than the phone to play. The picker lists: - this device; - AirPlay, through the system route picker; - each speaker Music Assistant knows, with what it's playing now; - a group of several speakers, which Music Assistant keeps in sync. Switching keeps the music going: the queue and position move to the new output. **The phone as a remote.** While a speaker is playing: - the lock screen and AirPods controls drive the speaker; - the phone's volume buttons change the speaker's volume, with a small on-screen level; - the phone keeps a silent audio session so iOS keeps routing those controls to the app. How it fits in: - `MusicAssistantClient` implements `MediaServerClient` for the parts that matter here. The rest say it is unsupported. Its library is never shown as a library. - `RoutedMusicPlaybackService` sits where `MusicPlaybackService` was provided. It runs the existing local engine when the output is this device, and `RemoteMusicPlaybackService` when it is a speaker. The local engine is unchanged. - `RemoteTrackUrlResolver` gives Music Assistant a stream URL for each Plex track. - On iOS: `AudioRoutePlugin` reports the system audio route, `BonjourDiscoveryPlugin` browses for servers (a raw multicast socket needs an entitlement Apple grants only on request), and `AppDelegate` watches the volume buttons and holds the silent session. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018jvpe7xbhMmZrv1agLChVA
Owner
|
Closing: out of scope. Music Assistant is a speaker router, not a media server, but this adds it as a fourth |
Owner
|
Open an issue before starting large changes so scope and approach can be agreed first. Unannounced PRs of this size are hard to review and are likely to be closed. |
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.
Lets you play your Plex music on Sonos and other speakers around the house, through Music Assistant.
Music Assistant is used only as a way to reach speakers. The music still comes from your Plex library and you browse it exactly as before; Music Assistant is told what to play and where. Its own library is never shown.
Adding a server
_mass._tcp) and lists what it finds. You can also type an address.Choosing where to play
Album and artist screens, the mini player and Now Playing get a speaker button whenever there's somewhere other than this device to play. The picker lists:
Switching output keeps the music going: the queue and position move to the new output.
The phone as a remote
While a speaker is playing:
How it fits in
MusicAssistantClientimplementsMediaServerClient(underlib/services/music_assistant_client/), on top ofMusicAssistantApi, which speaks Music Assistant's WebSocket protocol (lib/services/music_assistant/). Anything a music output has no use for returns empty or throwsUnsupportedError. A Music Assistant server is registered as output-only, so it never shows up as a library, in hubs, or in search.RoutedMusicPlaybackServiceis now what's provided asMusicPlaybackService. When the output is this device it runs the existing local engine, which is unchanged. When it's a speaker it runsRemoteMusicPlaybackService, which keeps the server's queue as the single source of truth and only displays what the server reports.RemoteTrackUrlResolvergives the speaker a stream URL for each Plex track, straight from the server (not a downloaded copy, which only exists on the phone).MediaBackend.musicAssistant, with the matching arm in each exhaustive switch.AudioRoutePluginreports the system audio route and shows the AirPlay picker.BonjourDiscoveryPluginbrowses for servers, because a raw multicast socket (what the Dart mDNS package uses) needs an entitlement Apple only grants on request.AppDelegatewatches the volume buttons and holds the silent session.Info.plistdeclares_mass._tcp.multicast_dnspackage.docs/music_assistant_protocol.mdrecords the parts of the WebSocket protocol this relies on, as observed against real servers (2.6 to 2.10).Things to know
RemoteMusicPlaybackService.playInstantMix, which I'll send as a follow-up.Tests:
test/music_assistant/(protocol, sign-in, paging, players, mappers, client, against a fake server),test/services/music/(output controller, routing, remote playback, now playing, volume buttons),add_music_assistant_screen_test.dart,output_picker_sheet_test.dart, discovery and server-manager registration.Screenshots
Add server: the Music Assistant card
A server found on the network (address hidden)
The speaker picker. Rendered with made-up speakers so as not to share my real ones
AI disclosure: written with Claude Opus 5 and Claude Opus 5.5 (Claude Code), reviewed and tested by me.
🤖 Generated with Claude Code
https://claude.ai/code/session_018jvpe7xbhMmZrv1agLChVA