Skip to content

Commit

Permalink
Fix status of child players (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiagoSotoC authored Dec 13, 2023
1 parent 0c9a45b commit ee06e50
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions music_assistant/server/providers/snapcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
CONF_SNAPCAST_SERVER_HOST = "snapcast_server_host"
CONF_SNAPCAST_SERVER_CONTROL_PORT = "snapcast_server_control_port"

SNAP_STREAM_STATUS_MAP = {
"idle": PlayerState.IDLE,
"playing": PlayerState.PLAYING,
"unknown": PlayerState.IDLE,
}


async def setup(
mass: MusicAssistant, manifest: ProviderManifest, config: ProviderConfig
Expand Down Expand Up @@ -156,6 +162,7 @@ def _handle_player_update(self, snap_client: SnapClient) -> None:
)
player.synced_to = self._synced_to(player_id)
player.group_childs = self._group_childs(player_id)
player.state = self._player_state(player_id)
self.mass.players.register_or_update(player)

async def unload(self) -> None:
Expand Down Expand Up @@ -225,6 +232,7 @@ async def on_start(arguments: list[str]):
player.elapsed_time = 0
player.elapsed_time_last_updated = time.time()
player.state = PlayerState.PLAYING
self._set_childs_state(player_id, PlayerState.PLAYING)
self.mass.players.register_or_update(player)

async def cmd_stop(self, player_id: str) -> None:
Expand All @@ -240,6 +248,7 @@ async def cmd_stop(self, player_id: str) -> None:
except FFmpegError:
self.logger.debug("Fail to stop ffmpeg player")
player.state = PlayerState.IDLE
self._set_childs_state(player_id, PlayerState.IDLE)
self.mass.players.register_or_update(player)

async def cmd_pause(self, player_id: str) -> None:
Expand Down Expand Up @@ -305,3 +314,15 @@ async def _get_empty_stream(self) -> str:
if "id" in new_stream and new_stream["id"] not in used_streams:
return new_stream["id"]
port += 1

def _player_state(self, player_id: str) -> PlayerState:
"""Return the state of the player."""
snap_group = self._get_snapgroup(player_id)
return SNAP_STREAM_STATUS_MAP.get(snap_group.stream_status)

def _set_childs_state(self, player_id: str, state: PlayerState) -> None:
"""Set the state of the child`s of the player."""
for child_player_id in self._group_childs(player_id):
player = self.mass.players.get(child_player_id)
player.state = state
self.mass.players.update(player)

0 comments on commit ee06e50

Please sign in to comment.