Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix snapcast provider in the dynamic generation of tcp streams #955

12 changes: 8 additions & 4 deletions music_assistant/server/providers/snapcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,12 @@ 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())
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)
ffmpeg = (
FFmpeg()
.option("y")
Expand All @@ -208,6 +211,7 @@ async def cmd_play_url(
ar=48000,
)
)

await self.cmd_stop(player_id)

ffmpeg_task = self.mass.create_task(ffmpeg.execute())
Expand Down Expand Up @@ -295,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://{self.snapcast_server_host}:{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"]
port += 1