Skip to content

Commit

Permalink
some small fixes/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Aug 25, 2024
1 parent 9313a0d commit 41421e4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion music_assistant/common/models/player_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class PlayerQueue(DataClassDictMixin):
flow_mode_start_index: int = 0
stream_finished: bool | None = None
end_of_track_reached: bool | None = None
queue_items_last_updated: float = time.time()
queue_version: str = ""

@property
def corrected_elapsed_time(self) -> float:
Expand Down
12 changes: 7 additions & 5 deletions music_assistant/server/controllers/player_queues.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from contextlib import suppress
from typing import TYPE_CHECKING, Any, TypedDict

import shortuuid

from music_assistant.common.helpers.util import get_changed_keys
from music_assistant.common.models.config_entries import (
ConfigEntry,
Expand Down Expand Up @@ -221,10 +223,7 @@ def get_active_queue(self, player_id: str) -> PlayerQueue:
if player.active_group and player.active_group != player.player_id:
return self.get_active_queue(player.active_group)
# active_source may be filled with other queue id
if player.active_source != player_id and (
queue := self.get_active_queue(player.active_source)
):
return queue
return self.get(player.active_source) or self.get(player_id)
return self.get(player_id)

# Queue commands
Expand Down Expand Up @@ -887,6 +886,7 @@ def on_player_update(
queue.state = player.state
queue.current_item = self.get_item(queue_id, queue.current_index)
queue.next_item = self._get_next_item(queue_id)

# correct elapsed time when seeking
if (
queue.current_item
Expand Down Expand Up @@ -934,6 +934,8 @@ def on_player_update(
# handle enqueuing of next item to play
if not queue.flow_mode or queue.stream_finished:
self._check_enqueue_next(player, queue, prev_state, new_state)

queue.resume_pos = queue.corrected_elapsed_time
# do not send full updates if only time was updated
if changed_keys == {"elapsed_time"}:
self.mass.signal_event(
Expand Down Expand Up @@ -1090,8 +1092,8 @@ def get_item(self, queue_id: str, item_id_or_index: int | str | None) -> QueueIt
def signal_update(self, queue_id: str, items_changed: bool = False) -> None:
"""Signal state changed of given queue."""
queue = self._queues[queue_id]
queue.queue_version = shortuuid.random(8)
if items_changed:
queue.queue_items_last_updated = time.time()
self.mass.signal_event(EventType.QUEUE_ITEMS_UPDATED, object_id=queue_id, data=queue)
# save items in cache
self.mass.create_task(
Expand Down
4 changes: 2 additions & 2 deletions music_assistant/server/controllers/streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ async def get_flow_stream(

# set some basic vars
pcm_sample_size = int(pcm_format.sample_rate * (pcm_format.bit_depth / 8) * 2)
crossfade_duration = await self.mass.config.get_player_config_value(
queue.queue_id, CONF_CROSSFADE_DURATION
crossfade_duration = self.mass.config.get_raw_player_config_value(
queue.queue_id, CONF_CROSSFADE_DURATION, 10
)
crossfade_size = int(pcm_sample_size * crossfade_duration)
bytes_written = 0
Expand Down
7 changes: 6 additions & 1 deletion music_assistant/server/providers/airplay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ async def play_media(
"""Handle PLAY MEDIA on given player."""
async with self._play_media_lock:
player = self.mass.players.get(player_id)
# set the active source for the player to the media queue
# this accounts for syncgroups and linked players (e.g. sonos)
player.active_source = media.queue_id
if player.synced_to:
# should not happen, but just in case
raise RuntimeError("Player is synced")
Expand Down Expand Up @@ -804,7 +807,9 @@ async def cmd_unsync(self, player_id: str) -> None:
group_leader.group_childs.remove(player_id)
player.synced_to = None
await self.cmd_stop(player_id)
self.mass.players.update(player_id)
# make sure that the player manager gets an update
self.mass.players.update(player.player_id, skip_forward=True)
self.mass.players.update(group_leader.player_id, skip_forward=True)

async def _getcliraop_binary(self):
"""Find the correct raop/airplay binary belonging to the platform."""
Expand Down

0 comments on commit 41421e4

Please sign in to comment.