From 9b2d057c6e041898819dd827465d1dab40e684ec Mon Sep 17 00:00:00 2001 From: repa Date: Wed, 8 Jan 2025 21:40:26 +0300 Subject: [PATCH] Fix change track, while playing to AirPlay receivers --- .../yandex_station/core/yandex_station.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/custom_components/yandex_station/core/yandex_station.py b/custom_components/yandex_station/core/yandex_station.py index a13b04d..41b2faf 100644 --- a/custom_components/yandex_station/core/yandex_station.py +++ b/custom_components/yandex_station/core/yandex_station.py @@ -984,6 +984,19 @@ async def sync_play_media(self, player_state: dict): source = self.sync_sources[self._attr_source] + #For AirPlay receivers is not possible to change media_content_id, while streaming to device is in progress + #So we need to send media_stop command to media_player instance + #And after streaming is stopped we can send to device new media_content_id + #If we don't do this we got error "already streaming to device" + #Error provided by pyatv component https://github.com/postlund/pyatv + #https://github.com/postlund/pyatv/blob/master/pyatv/protocols/raop/__init__.py at line 132 + data_stop = { + "entity_id": source["entity_id"], + } + await self.hass.services.async_call("media_player", "media_stop", data_stop) + #After command is sended, we need to wait while receiver accept command and stop streaming + await asyncio.sleep(1) + try: info = await get_file_info( self.quasar.session,