Skip to content

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.

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
  • A player provider does not own players. For every way it reaches a device, it builds a PlayerProtocol subclass and calls mass.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 runs derive_player_state over what all its protocols report, plus the user’s config, and publishes the result as a PlayerState. A PLAYER_UPDATED event goes out only when something changed.
  • Every player has one queue. Its queue_id is the player_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. Speakers can play in sync as a group. A group player, such as one of the sync_group or universal_group provider, has a VIRTUAL protocol and decides its own members. How a group change reaches the devices is planned in grouping_plan.py and carried out by apply_group_change in grouping.py, both in controllers/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.

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.
  • available and available_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.

Music Assistant is a project of the Open Home Foundation.