Players
One speaker can often be reached in several ways: its vendor’s own protocol, AirPlay, Chromecast, DLNA. This page helps you understand how Music Assistant turns all of those into one player that users and clients see, and where to look before you change anything in it.
One device, one player
Section titled “One device, one player”flowchart LR SONOS["Sonos provider<br/>PlayerProtocol, role NATIVE"] AIR["AirPlay provider<br/>PlayerProtocol, role AUDIO"] CAST["Chromecast provider<br/>PlayerProtocol, role AUDIO"] REG["mass.players.register"] P["Player<br/>owned by the player controller"] DER["derive_player_state"] PS["PlayerState<br/>published snapshot"] Q["PlayerQueue<br/>queue_id is player_id"] CL["Clients"] SONOS --> REG AIR --> REG CAST --> REG REG -->|"attach"| P P --> DER DER --> PS PS -->|"PLAYER_UPDATED"| CL P --- Q
How to read this
Section titled “How to read this”- A player provider does not own players. For every way it reaches a device, it builds a
PlayerProtocolsubclass and callsmass.players.register(protocol). - The player controller decides which player each protocol belongs to and attaches it. Three providers that reach the same speaker end up on one
Player. - When a protocol reports a change, it calls
update_state(). The player then runsderive_player_stateover what all its protocols report, plus the user’s config, and publishes the result as aPlayerState. APLAYER_UPDATEDevent goes out only when something changed. - Every player has one queue. Its
queue_idis theplayer_id. - Commands go the other way: the controller routes each command to the protocol that has to carry it out.
A player outlives its protocols. It is created from its stored config at startup, before any provider loads, and stays listed, unavailable, while its device is away.
What a protocol is for its device is its ProtocolRole:
NATIVE: the vendor’s own control plane.CONTROL: control without an audio path of its own; playback goes through an audio protocol of the same device.AUDIO: an audio protocol of the device, such as AirPlay, Chromecast or DLNA.VIRTUAL: the protocol of a group player.
When playback starts, the controller picks the protocol that plays the audio (the output): a protocol that is grouped right now, else the one the user prefers, else the own protocol when it can play media itself, else the audio protocol the own protocol prefers, else the best audio protocol by priority. That choice is made in controllers/players/outputs.py.
Groups and multi-channel sets
Section titled “Groups and multi-channel sets”- Groups. Speakers can play in sync as a group. A group player, such as one of the
sync_grouporuniversal_groupprovider, has aVIRTUALprotocol and decides its own members. How a group change reaches the devices is planned ingrouping_plan.pyand carried out byapply_group_changeingrouping.py, both incontrollers/players/. - Multi-channel sets. A stereo pair or a home theater set is one player of type
MULTI_CHANNEL. The protocol of the primary speaker delivers the set; the other speakers of the set have no player of their own.
Terms you need
Section titled “Terms you need”These follow the definitions in the players README.
PlayerProtocol: the provider’s handle on one device over one protocol.Player: the player users, clients and the queue see; it gives the final value of every field of its state. Owned by the controller and never subclassed.PlayerState: the published snapshot of a player, what the API sends.PlayerConfig: what is stored about a player or a protocol. The config controller owns it.own_protocol: the protocol that stands for the device itself (native, else control, else virtual).audio_protocols: the audio protocols of the player, most preferred first.availableandavailable_for_playback: clients can use the player, versus it can be played to right now.- Player id: minted by the controller. Nothing may assume that a player id is the id of one of its protocols.
- Legacy ids: ids a player was known under before, such as the id of a player that was merged into it.
IMPORTANT
Read the players README before you change the player controller or a player provider. Identity, merging, power, volume and locking each have rules there that are easy to break.
Read deeper
Section titled “Read deeper”- players README: the full model, identity and matching, lifecycle, config storage, commands, grouping, locking, and what a provider has to do.
- models/player_protocol.py: the
PlayerProtocolbase class with its hooks. - discovery README: how a provider learns a device is on the network.
- Providers and From play to sound
Music Assistant is a project of the Open Home Foundation.