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

Can't play to multiple camera media_players at the same time #660

Open
borgqueenx opened this issue Feb 28, 2024 · 5 comments
Open

Can't play to multiple camera media_players at the same time #660

borgqueenx opened this issue Feb 28, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@borgqueenx
Copy link

borgqueenx commented Feb 28, 2024

I have around 8 camera's that i use as media_player in configuration.yaml and i can send audio files to all of them.
However when i try to send a audio file to 2 media players at the same time, it plays it on just 1 camera and the other is ignored. after waiting a bit i get a "error", without it saying what the error exactly is.

In the home assistant core logs, i find the following that could be related:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/webrtc/media_player.py:74
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 17:20:32 (2 occurrences)
Last logged: 17:21:59

[139646349665088] Error handling message: Unknown error (unknown_error) borgqueenx from 100.82.15.21 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36)
[139646411738432] Error handling message: Unknown error (unknown_error) borgqueenx from 100.82.15.21 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 782, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1587, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 426, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 479, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 502, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 713, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 675, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 907, in entity_service_call
    raise result from None
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1497, in async_request_call
    return await coro
           ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/webrtc/media_player.py", line 74, in async_play_media
    assert r.ok
AssertionError

If i try to make multiple actions, each with the same sound to just 1 mediaplayer entity, it works, but with delays of course, so its not ideal.

@AlexxIT AlexxIT added the bug Something isn't working label Feb 28, 2024
@AlexxIT
Copy link
Owner

AlexxIT commented Feb 28, 2024

Show how you call service

@borgqueenx
Copy link
Author

borgqueenx commented Feb 28, 2024

This is how:

service: media_player.play_media
metadata:
  title: wolf-howl.mp3
  thumbnail: null
  media_class: music
  children_media_class: null
  navigateIds:
    - {}
    - media_content_type: app
      media_content_id: media-source://media_source
    - media_content_type: ""
      media_content_id: media-source://media_source/local/sounds
data:
  media_content_id: media-source://media_source/local/sounds/dog_barking.mp3
  media_content_type: audio/mpeg
target:
  entity_id:
    - media_player.poolpole_cam
    - media_player.bedroom_top
    - media_player.living_room

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 7, 2024

Show how you setup media_player. Are you sure it support two way audio and you choose right audio codec?

@borgqueenx
Copy link
Author

borgqueenx commented Apr 13, 2024

Show how you setup media_player. Are you sure it support two way audio and you choose right audio codec?

do you have suggestions what codec to use? they are added using frigate, most of them using the tapo protocol. I also notice on all my camera's that the sound crackles/lags the first time playing something after a while. if i then repeat the same command immediately after, it's usually playing fine. perhaps i should first play a empty sound and then play the actual sound, it might improve it.
Two-way audio definitely works, i can use home assistant to talk to the tapo cameras.

Here is the YAML to execute playing a sound on a tapo camera:

service: media_player.play_media
metadata:
title: carlock.mp3
thumbnail: null
media_class: music
children_media_class: null
navigateIds:
- {}
- media_content_type: app
media_content_id: media-source://media_source
- media_content_type: ""
media_content_id: media-source://media_source/local/sounds
data:
media_content_id: media-source://media_source/local/sounds/carlock.mp3
media_content_type: audio/mpeg
target:
entity_id: media_player.house_corner_garden_view

And this is how the cameras are added in frigate:

go2rtc:
streams:
kitchen-cam:
- tapo://Tomaat66-@192.168.1.182
- ffmpeg:kitchen-cam#audio=aac

(the aac is needed or else recordings will not have sound)

And finally, this is the part from the home assistant configuration.yaml how the media players are added.
All tapo camera's are pcma.
The camera's all the way below are not tapo cameras but annke cameras.

media_player:
  - platform: webrtc
    name: living-room
    stream: living-room
    audio: pcma
  - platform: webrtc
    name: naelis-place
    stream: naelis-place
    audio: pcma
  - platform: webrtc
    name: bedroom-top
    stream: bedroom-top
    audio: pcma
  - platform: webrtc
    name: bedroom-floor
    stream: bedroom-floor
    audio: pcma
  - platform: webrtc
    name: outdoor-arch
    stream: outdoor-arch
    audio: pcma
  - platform: webrtc
    name: kitchen-cam
    stream: kitchen-cam
    audio: pcma
  - platform: webrtc
    name: hallway-cam
    stream: hallway-cam
    audio: pcma
  - platform: webrtc
    name: billiard-room
    stream: billiard-room
    audio: pcma
  - platform: webrtc
    name: house-corner-garden-view
    stream: house-corner-garden-view
    audio: pcmu/8000
  - platform: webrtc
    name: poolpole-cam
    stream: poolpole-cam
    audio: pcmu/8000
  - platform: webrtc
    name: garage-door
    stream: garage-door
    audio: pcmu/8000

@AlexxIT
Copy link
Owner

AlexxIT commented Apr 15, 2024

Tapo cameras uses audio: pcma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants