From 98013438f0037b2c364ada004719208ca5d52ae2 Mon Sep 17 00:00:00 2001 From: Santiago Soto Date: Wed, 6 Dec 2023 18:39:35 -0300 Subject: [PATCH 1/5] Update snapstream to use 127.0.0.1 Snapcast expects ip to be 127.0.0.1 in tcp server mode --- music_assistant/server/providers/snapcast/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/music_assistant/server/providers/snapcast/__init__.py b/music_assistant/server/providers/snapcast/__init__.py index a21ff0c12..069f15594 100644 --- a/music_assistant/server/providers/snapcast/__init__.py +++ b/music_assistant/server/providers/snapcast/__init__.py @@ -297,7 +297,7 @@ async def _get_empty_stream(self) -> str: while True: port += 1 new_stream = await self._snapserver.stream_add_stream( - f"tcp://{self.snapcast_server_host}:{port}?name={name}" + f"tcp://127.0.0.1:{port}?name={name}" ) if new_stream["id"] not in used_streams: return new_stream["id"] From aa5b834ace48977450d0a7665a407a9a1e5c6bc0 Mon Sep 17 00:00:00 2001 From: Santiago Soto Date: Wed, 6 Dec 2023 20:38:52 -0300 Subject: [PATCH 2/5] Update snapstream to use 0.0.0.0 --- music_assistant/server/providers/snapcast/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/music_assistant/server/providers/snapcast/__init__.py b/music_assistant/server/providers/snapcast/__init__.py index 069f15594..b278da88c 100644 --- a/music_assistant/server/providers/snapcast/__init__.py +++ b/music_assistant/server/providers/snapcast/__init__.py @@ -195,6 +195,7 @@ async def cmd_play_url( await self._get_snapgroup(player_id).set_stream(await self._get_empty_stream()) stream_host = stream._stream.get("uri").get("host") + stream_host = stream_host.replace("0.0.0.0", self.snapcast_server_host) ffmpeg = ( FFmpeg() .option("y") @@ -208,6 +209,7 @@ async def cmd_play_url( ar=48000, ) ) + await self.cmd_stop(player_id) ffmpeg_task = self.mass.create_task(ffmpeg.execute()) @@ -297,7 +299,7 @@ async def _get_empty_stream(self) -> str: while True: port += 1 new_stream = await self._snapserver.stream_add_stream( - f"tcp://127.0.0.1:{port}?name={name}" + f"tcp://0.0.0.0:{port}?name={name}" ) - if new_stream["id"] not in used_streams: + if "id" in new_stream and new_stream["id"] not in used_streams: return new_stream["id"] From 9c5aebc14bb7523c6e225f813ebc0f0713dcb8a6 Mon Sep 17 00:00:00 2001 From: Santiago Soto Date: Wed, 6 Dec 2023 20:52:35 -0300 Subject: [PATCH 3/5] Fix stream handling and player state update --- music_assistant/server/providers/snapcast/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/music_assistant/server/providers/snapcast/__init__.py b/music_assistant/server/providers/snapcast/__init__.py index b278da88c..e1ab127c7 100644 --- a/music_assistant/server/providers/snapcast/__init__.py +++ b/music_assistant/server/providers/snapcast/__init__.py @@ -193,6 +193,7 @@ async def cmd_play_url( stream = self._get_snapstream(player_id) if stream.path != "": await self._get_snapgroup(player_id).set_stream(await self._get_empty_stream()) + stream = self._get_snapstream(player_id) stream_host = stream._stream.get("uri").get("host") stream_host = stream_host.replace("0.0.0.0", self.snapcast_server_host) From aa9693120c65e23e18ec8ee5e81f50fc6817eefb Mon Sep 17 00:00:00 2001 From: Santiago Soto Date: Wed, 6 Dec 2023 22:44:05 -0300 Subject: [PATCH 4/5] Fix stream handling in SnapCast Provider --- music_assistant/server/providers/snapcast/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/music_assistant/server/providers/snapcast/__init__.py b/music_assistant/server/providers/snapcast/__init__.py index e1ab127c7..657332dfc 100644 --- a/music_assistant/server/providers/snapcast/__init__.py +++ b/music_assistant/server/providers/snapcast/__init__.py @@ -192,8 +192,9 @@ async def cmd_play_url( player = self.mass.players.get(player_id) stream = self._get_snapstream(player_id) if stream.path != "": - await self._get_snapgroup(player_id).set_stream(await self._get_empty_stream()) - stream = self._get_snapstream(player_id) + new_stream_id = await self._get_empty_stream() + await self._get_snapgroup(player_id).set_stream(new_stream_id) + stream = self._snapserver.stream(new_stream_id) stream_host = stream._stream.get("uri").get("host") stream_host = stream_host.replace("0.0.0.0", self.snapcast_server_host) @@ -298,9 +299,9 @@ async def _get_empty_stream(self) -> str: port = 4953 name = str(uuid.uuid4()) while True: - port += 1 new_stream = await self._snapserver.stream_add_stream( f"tcp://0.0.0.0:{port}?name={name}" ) + port += 1 if "id" in new_stream and new_stream["id"] not in used_streams: return new_stream["id"] From 912dab5aaa0ef5301f6ec3def26b300ba54978f0 Mon Sep 17 00:00:00 2001 From: Santiago Soto Date: Thu, 7 Dec 2023 21:26:48 -0300 Subject: [PATCH 5/5] Port increment optimization --- music_assistant/server/providers/snapcast/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/music_assistant/server/providers/snapcast/__init__.py b/music_assistant/server/providers/snapcast/__init__.py index 657332dfc..72c20db54 100644 --- a/music_assistant/server/providers/snapcast/__init__.py +++ b/music_assistant/server/providers/snapcast/__init__.py @@ -302,6 +302,6 @@ async def _get_empty_stream(self) -> str: new_stream = await self._snapserver.stream_add_stream( f"tcp://0.0.0.0:{port}?name={name}" ) - port += 1 if "id" in new_stream and new_stream["id"] not in used_streams: return new_stream["id"] + port += 1