Skip to content

Commit

Permalink
Fix: only send the bypass_proxy data to esphome players
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Dec 20, 2024
1 parent b812a2f commit 855b999
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions music_assistant/providers/hass_players/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,29 +255,34 @@ async def play_media(self, player_id: str, media: PlayerMedia) -> None:
"""Handle PLAY MEDIA on given player."""
if self.mass.config.get_raw_player_config_value(player_id, CONF_ENFORCE_MP3, True):
media.uri = media.uri.replace(".flac", ".mp3")
player = self.mass.players.get(player_id, True)
assert player
extra_data = {
# passing metadata to the player
# so far only supported by google cast, but maybe others can follow
"metadata": {
"title": media.title,
"artist": media.artist,
"metadataType": 3,
"album": media.album,
"albumName": media.album,
"images": [{"url": media.image_url}] if media.image_url else None,
"imageUrl": media.image_url,
},
}
if player.extra_data.get("hass_domain") == "esphome":
# tell esphome mediaproxy to bypass the proxy,
# as MA already delivers an optimized stream
extra_data["bypass_proxy"] = True

await self.hass_prov.hass.call_service(
domain="media_player",
service="play_media",
service_data={
"media_content_id": media.uri,
"media_content_type": "music",
"enqueue": "replace",
"extra": {
# passing metadata to the player
# so far only supported by google cast, but maybe others can follow
"metadata": {
"title": media.title,
"artist": media.artist,
"metadataType": 3,
"album": media.album,
"albumName": media.album,
"images": [{"url": media.image_url}] if media.image_url else None,
"imageUrl": media.image_url,
},
# tell esphome mediaproxy to bypass the proxy,
# as MA already delivers an optimized stream
"bypass_proxy": True,
},
"extra": extra_data,
},
target={"entity_id": player_id},
)
Expand Down

0 comments on commit 855b999

Please sign in to comment.