Fix: stop airplay playback when player reports it has become inactive
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 2 May 2025 15:03:57 +0000 (17:03 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 2 May 2025 15:03:57 +0000 (17:03 +0200)
music_assistant/providers/airplay/provider.py
music_assistant/providers/airplay/raop.py

index 1312ab437e9085490e01dbfab4e7fa3cbd12f033..14e9a5e6a12e659dde66bf95e841f68dcf67fd0a 100644 (file)
@@ -654,13 +654,9 @@ class AirPlayProvider(PlayerProvider):
             elif "device-prevent-playback=1" in path:
                 # device switched to another source (or is powered off)
                 if raop_stream := airplay_player.raop_stream:
-                    # ignore this if we just started playing to prevent false positives
-                    elapsed_time = (
-                        10 if mass_player.elapsed_time is None else mass_player.elapsed_time
+                    self.mass.create_task(
+                        airplay_player.raop_stream.session.remove_client(airplay_player)
                     )
-                    if elapsed_time > 10 and mass_player.state == PlayerState.PLAYING:
-                        raop_stream.prevent_playback = True
-                        self.mass.create_task(self.monitor_prevent_playback(player_id))
             elif "device-prevent-playback=0" in path:
                 # device reports that its ready for playback again
                 if raop_stream := airplay_player.raop_stream:
@@ -678,30 +674,3 @@ class AirPlayProvider(PlayerProvider):
             await writer.drain()
         finally:
             writer.close()
-
-    async def monitor_prevent_playback(self, player_id: str) -> None:
-        """Monitor the prevent playback state of an airplay player."""
-        count = 0
-        if not (airplay_player := self._players.get(player_id)):
-            return
-        if not airplay_player.raop_stream:
-            return
-        prev_active_remote_id = airplay_player.raop_stream.active_remote_id
-        while count < 40:
-            count += 1
-            if not (airplay_player := self._players.get(player_id)):
-                return
-            if not (raop_stream := airplay_player.raop_stream):
-                return
-            if raop_stream.active_remote_id != prev_active_remote_id:
-                # checksum
-                return
-            if not raop_stream.prevent_playback:
-                return
-            await asyncio.sleep(0.5)
-
-        if airplay_player.raop_stream and airplay_player.raop_stream.session:
-            airplay_player.logger.info(
-                "Player has been in prevent playback mode for too long, aborting playback.",
-            )
-            await airplay_player.raop_stream.session.remove_client(airplay_player)
index ad18e568e2f85fc22ad34298bc99c016eb6ebdab..e71a4be4f75e540e16e567bb82fd0b5a75f91dee 100644 (file)
@@ -100,7 +100,7 @@ class RaopStreamSession:
         assert airplay_player.raop_stream.session == self
         async with self._lock:
             self._sync_clients.remove(airplay_player)
-        await airplay_player.raop_stream.stop()
+        await airplay_player.cmd_stop()
         airplay_player.raop_stream = None
 
     async def add_client(self, airplay_player: AirPlayPlayer) -> None: