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

Snapcast fix short announcements #1743

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions music_assistant/server/providers/snapcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
from music_assistant.common.models.errors import SetupFailedError
from music_assistant.common.models.media_items import AudioFormat
from music_assistant.common.models.player import DeviceInfo, Player, PlayerMedia
from music_assistant.server.helpers.audio import FFMpeg, get_ffmpeg_stream, get_player_filter_params
from music_assistant.server.helpers.audio import (
FFMpeg,
get_ffmpeg_stream,
get_player_filter_params,
)
from music_assistant.server.helpers.process import AsyncProcess, check_output
from music_assistant.server.models.player_provider import PlayerProvider

Expand Down Expand Up @@ -559,12 +563,17 @@ async def _streamer() -> None:
self.mass.players.update(player_id)
self._set_childs_state(player_id)
finally:
with suppress(TypeError, KeyError, AttributeError):
await self._snapserver.stream_remove_stream(stream.identifier)
await self._delete_current_snapstream(stream, media)

# start streaming the queue (pcm) audio in a background task
self._stream_tasks[player_id] = asyncio.create_task(_streamer())

async def _delete_current_snapstream(self, stream, media):
SantiagoSotoC marked this conversation as resolved.
Show resolved Hide resolved
with suppress(TypeError, KeyError, AttributeError):
if media.duration < 5:
await asyncio.sleep(5)
marcelveldt marked this conversation as resolved.
Show resolved Hide resolved
await self._snapserver.stream_remove_stream(stream.identifier)

def _get_snapgroup(self, player_id: str) -> Snapgroup:
"""Get snapcast group for given player_id."""
snap_client_id = self._get_snapclient_id(player_id)
Expand Down Expand Up @@ -628,7 +637,9 @@ async def _create_default_stream(self) -> None:
"""Create new stream on snapcast server named default case not exist."""
all_streams = {stream.name for stream in self._snapserver.streams}
if "default" not in all_streams:
await self._snapserver.stream_add_stream("pipe:///tmp/snapfifo?name=default")
await self._snapserver.stream_add_stream(
"pipe:///tmp/snapfifo?name=default&sampleformat=48000:16:2"
)

def _set_childs_state(self, player_id: str) -> None:
"""Set the state of the child`s of the player."""
Expand Down