Skip to content

feat(music): play to Sonos and other speakers through Music Assistant - #3078

Closed
JackDanger wants to merge 1 commit into
edde746:mainfrom
JackDanger:music-assistant-speakers
Closed

JackDanger wants to merge 1 commit into
edde746:mainfrom
JackDanger:music-assistant-speakers

Conversation

@JackDanger

@JackDanger JackDanger commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Settings → Add server gets a fourth card, "Connect to Music Assistant".
  • The app looks for servers on the local network (Bonjour, _mass._tcp) and lists what it finds. You can also type an address.
  • Servers from 2.10 on need a sign-in, using the same username and password as Music Assistant's 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's somewhere other than this device to play. The picker lists:

  • this device;
  • AirPlay, through the system route picker;
  • every speaker Music Assistant knows, with whether it's playing something else;
  • a group of several speakers, which Music Assistant keeps in sync. Creating a group needs a Music Assistant admin account, and the app says so if the account can't.

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:

  • 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 sending those controls to the app.

How it fits in

  • MusicAssistantClient implements MediaServerClient (under lib/services/music_assistant_client/), on top of MusicAssistantApi, which speaks Music Assistant's WebSocket protocol (lib/services/music_assistant/). Anything a music output has no use for returns empty or throws UnsupportedError. A Music Assistant server is registered as output-only, so it never shows up as a library, in hubs, or in search.
  • RoutedMusicPlaybackService is now what's provided as MusicPlaybackService. When the output is this device it runs the existing local engine, which is unchanged. When it's a speaker it runs RemoteMusicPlaybackService, which keeps the server's queue as the single source of truth and only displays what the server reports.
  • RemoteTrackUrlResolver gives the speaker a stream URL for each Plex track, straight from the server (not a downloaded copy, which only exists on the phone).
  • New MediaBackend.musicAssistant, with the matching arm in each exhaustive switch.
  • iOS: AudioRoutePlugin reports the system audio route and shows the AirPlay picker. BonjourDiscoveryPlugin browses for servers, because a raw multicast socket (what the Dart mDNS package uses) needs an entitlement Apple only grants on request. AppDelegate watches the volume buttons and holds the silent session. Info.plist declares _mass._tcp.
  • Other platforms discover servers with the multicast_dns package.
  • docs/music_assistant_protocol.md records the parts of the WebSocket protocol this relies on, as observed against real servers (2.6 to 2.10).

Things to know

  • Tested on iPhone with a Music Assistant 2.10 server and Sonos speakers. I haven't tried Android or desktop against a real server.
  • This and the Radio PR (feat(music): Radio and Shuffle for a music library, and Radio that keeps playing #3077) are independent. If both land, Radio on a speaker should also top up its queue as Radio does on the phone. That's a few lines in 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

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
Copilot AI balanced review requested due to automatic review settings November 14, 2026 17:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@edde746

edde746 commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Closing: out of scope. Music Assistant is a speaker router, not a media server, but this adds it as a fourth MediaBackend, a MediaItem variant, and a MediaServerClient whose unsupported surface is 329 lines of stubs, then filters it back out with is MusicAssistantClient checks in MultiServerManager. It also ships library browsing for a library the description says is never shown, and keeps a silent audio loop running on iOS to hold remote commands. Untested on Android and desktop. At 19k lines this is better kept as a fork.

@edde746 edde746 closed this Nov 14, 2026
@edde746

edde746 commented Nov 14, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants