Build a player provider
A player provider reaches a kind of speaker, such as Sonos, Chromecast or AirPlay. It does not own players: the player controller does. Players explains how one device reached in several ways becomes one player.
Start from _demo_player_provider: provider.py holds the provider, player.py the protocol of one device.
Protocols, not players
Section titled “Protocols, not players”- For each device it reaches, your provider builds a subclass of
PlayerProtocoland callsawait mass.players.register(protocol). - The controller finds or creates the
Playerof that device and attaches your protocol to it, which can be afterregisterreturns:on_attach()tells you when. The protocol then finds its player asself.player. - When the device goes away, call
mass.players.unregister(protocol_id). When your provider forgets the device, callmass.players.remove_protocol(protocol_id). - Features of the provider itself, such as
CREATE_GROUP_PLAYER, go to the constructor as a set, as for any provider.
What a protocol reports
Section titled “What a protocol reports”A protocol reports what its device is and does through its _attr_* values, or by overriding the matching properties:
_attr_role: what the protocol is for the device (ProtocolRole:NATIVE,CONTROL,AUDIOorVIRTUAL)._attr_typeand_attr_supported_features._attr_device_info, with every identifier the device really has (MAC address, UUID, serial number). The controller matches protocols to devices on them.- The state:
_attr_powered,_attr_volume_level,_attr_playback_state,_attr_current_mediaand the like.
It also carries out the commands: play_media(), stop(), pause(), volume_set(), power() and the others its features allow.
To publish a change, set the _attr_* values and call self.update_state(). The player then derives its state from all its protocols and sends PLAYER_UPDATED when something changed.
Discovery
Section titled “Discovery”List what your provider listens for in its manifest:
{ "mdns_discovery": ["_demo_service_type._tcp.local."], "upnp_discovery": ["urn:schemas-upnp-org:device:MediaRenderer:1"]}mdns_discoverytakes Zeroconf service types; the server callson_mdns_service_state_change()for each change.upnp_discoverytakes SSDP search targets; the server callson_upnp_service_discovered().discover_players()registers the known devices that these cannot reach, such as a list in the config. The server calls it when the provider loads and whenever a device may be found again, and replays the cached mDNS records and SSDP searches at the same moments.
The discovery README covers how the server listens.
The contract
Section titled “The contract”IMPORTANT
A protocol has to follow rules about the values it reads, grouping, power and the order of on_attach() and on_detach(). Read What a Provider Has to Do in the players README before you write one.
Music Assistant is a project of the Open Home Foundation.