From: Marcel van der Veldt Date: Tue, 18 Feb 2025 16:29:51 +0000 (+0100) Subject: Fix enqueue next if player is already playing X-Git-Url: https://git.kitaultman.com/?a=commitdiff_plain;h=6dd24ed759642569ed132d2569a5715c2b495373;p=music-assistant-server.git Fix enqueue next if player is already playing --- diff --git a/music_assistant/controllers/player_queues.py b/music_assistant/controllers/player_queues.py index 8a2fcc73..93459cfb 100644 --- a/music_assistant/controllers/player_queues.py +++ b/music_assistant/controllers/player_queues.py @@ -463,7 +463,7 @@ class PlayerQueuesController(CoreController): # load the items into the queue if queue.state in (PlayerState.PLAYING, PlayerState.PAUSED): - cur_index = queue.index_in_buffer or 0 + cur_index = queue.index_in_buffer or queue.current_index or 0 else: cur_index = queue.current_index or 0 insert_at_index = cur_index + 1 if self._queue_items.get(queue_id) else 0 @@ -1090,6 +1090,7 @@ class PlayerQueuesController(CoreController): - keep_remaining: keep the remaining items after the insert - shuffle: (re)shuffle the items after insert index """ + queue = self._queues[queue_id] prev_items = self._queue_items[queue_id][:insert_at_index] if keep_played else [] next_items = queue_items @@ -1105,6 +1106,23 @@ class PlayerQueuesController(CoreController): next_items = random.sample(next_items, len(next_items)) self.update_items(queue_id, prev_items + next_items) + # if the next index changed we need to tell the player to enqueue the (new) next item + index_in_buffer = queue.index_in_buffer or queue.current_index or 0 + if ( + insert_at_index == (index_in_buffer + 1) + and queue.state != PlayerState.IDLE + and not queue.flow_mode + and (current_item_in_buffer := self.get_item(queue_id, index_in_buffer)) + ): + task_id = f"enqueue_next_item_{queue_id}" + self.mass.call_later( + 1, + self._enqueue_next_item, + queue_id, + current_item_in_buffer.queue_item_id, + task_id=task_id, + ) + def update_items(self, queue_id: str, queue_items: list[QueueItem]) -> None: """Update the existing queue items, mostly caused by reordering.""" self._queue_items[queue_id] = queue_items