fix race condition while playing announcements
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 22 Jul 2022 14:44:38 +0000 (16:44 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 22 Jul 2022 14:44:38 +0000 (16:44 +0200)
music_assistant/controllers/streams.py
music_assistant/models/player_queue.py

index deecdff679794bb773dad4f3b2c64981caea3a68..f1f8ae8dacfed0b0d608e456b58492e0185ea585 100644 (file)
@@ -493,7 +493,7 @@ class QueueStream:
                         self.connected_clients.pop(client_id, None)
 
             # complete queue streamed
-            if self.signal_next:
+            if self.signal_next and not self.queue.announcement_in_progress:
                 # the queue stream was aborted (e.g. because of sample rate mismatch)
                 # tell the queue to load the next track (restart stream) as soon
                 # as the player finished playing and returns to idle
index 584210655860d111c18ca3783d392c6d383ccea6..28a1c0e4811779c09af4fbdfbb093de97d13c9a9 100644 (file)
@@ -81,7 +81,7 @@ class PlayerQueue:
         self._last_player_update: int = 0
         self._last_stream_id: str = ""
         self._snapshot: Optional[QueueSnapShot] = None
-        self._announcement_in_progress: bool = False
+        self.announcement_in_progress: bool = False
 
     async def setup(self) -> None:
         """Handle async setup of instance."""
@@ -211,7 +211,7 @@ class PlayerQueue:
                 QueueOption.ADD -> Append new items at end of the queue
             :param passive: if passive set to true the stream url will not be sent to the player.
         """
-        if self._announcement_in_progress:
+        if self.announcement_in_progress:
             self.logger.warning("Ignore queue command: An announcement is in progress")
             return
         # a single item or list of items may be provided
@@ -285,7 +285,7 @@ class PlayerQueue:
         url: URL that should be played as announcement, can only be plain url.
         prepend_alert: Prepend the (TTS) announcement with an alert bell sound.
         """
-        if self._announcement_in_progress:
+        if self.announcement_in_progress:
             self.logger.warning(
                 "Ignore queue command: An announcement is (already) in progress"
             )
@@ -317,7 +317,7 @@ class PlayerQueue:
                 PlayerState.PAUSED,
             ):
                 await self.stop()
-                self._announcement_in_progress = True
+                self.announcement_in_progress = True
                 await self._wait_for_state((PlayerState.OFF, PlayerState.IDLE))
 
             # turn on player if needed
@@ -369,12 +369,12 @@ class PlayerQueue:
             self.logger.exception("Error while playing announcement", exc_info=err)
         finally:
             # restore queue
-            self._announcement_in_progress = False
+            self.announcement_in_progress = False
             await self.snapshot_restore()
 
     async def stop(self) -> None:
         """Stop command on queue player."""
-        if self._announcement_in_progress:
+        if self.announcement_in_progress:
             self.logger.warning("Ignore queue command: An announcement is in progress")
             return
         self.signal_next = False
@@ -383,7 +383,7 @@ class PlayerQueue:
 
     async def play(self) -> None:
         """Play (unpause) command on queue player."""
-        if self._announcement_in_progress:
+        if self.announcement_in_progress:
             self.logger.warning("Ignore queue command: An announcement is in progress")
             return
         if self.player.state == PlayerState.PAUSED:
@@ -393,7 +393,7 @@ class PlayerQueue:
 
     async def pause(self) -> None:
         """Pause command on queue player."""
-        if self._announcement_in_progress:
+        if self.announcement_in_progress:
             self.logger.warning("Ignore queue command: An announcement is in progress")
             return
         # redirect to underlying player
@@ -516,7 +516,7 @@ class PlayerQueue:
         passive: bool = False,
     ) -> None:
         """Play item at index (or item_id) X in queue."""
-        if self._announcement_in_progress:
+        if self.announcement_in_progress:
             self.logger.warning("Ignore queue command: An announcement is in progress")
             return
         if not isinstance(index, int):
@@ -655,7 +655,7 @@ class PlayerQueue:
         cur_player_state = (self.player.state.value, self.player.current_url)
         if self._last_player_state != cur_player_state:
             # playback state changed
-            if self._announcement_in_progress:
+            if self.announcement_in_progress:
                 # while announcement in progress dont update the last url
                 # to allow us to resume from 3rd party sources
                 # https://github.com/music-assistant/hass-music-assistant/issues/697