Stream to apple TV Error Failed to call service "already streaming to device"

I cant get any media to stream to my new apple tv integration. I can control the apple Tv and change the app and use the remote but when i try to airplay a local file i get the following error:

Failed to call service media_player/play_media. already streaming to device

I dont understand why because i am not streaming to the apple tv. this happens from any media source. I have tried deleting and re connecting the integration with no luck. Has anyone run into this issue?

I am running Home assistant core on a raspberry pi.

here is the full error logs

Logger: homeassistant.components.websocket_api.http.connection
Source: components/apple_tv/media_player.py:297
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 1:21:45 PM (10 occurrences)
Last logged: 1:41:11 PM

[547139197632] already streaming to device
[547141705200] already streaming to device
[547061415840] already streaming to device
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/websocket_api/commands.py", line 189, in handle_call_service
    await hass.services.async_call(
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 1627, in async_call
    task.result()
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/core.py", line 1664, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await service.entity_service_call(
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 677, in entity_service_call
    future.result()  # pop exception if have
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/entity.py", line 964, in async_request_call
    await coro
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 714, in _handle_entity_call
    await result
  File "/srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/apple_tv/media_player.py", line 297, in async_play_media
    await self.atv.stream.stream_file(media_id)
  File "/srv/homeassistant/lib/python3.9/site-packages/pyatv/core/facade.py", line 382, in stream_file
    await self.relay("stream_file")(file, **kwargs)
  File "/srv/homeassistant/lib/python3.9/site-packages/pyatv/protocols/raop/__init__.py", line 341, in stream_file
    self.playback_manager.acquire()
  File "/srv/homeassistant/lib/python3.9/site-packages/pyatv/protocols/raop/__init__.py", line 141, in acquire
    raise exceptions.InvalidStateError("already streaming to device")
pyatv.exceptions.InvalidStateError: already streaming to device

Same issue by me

Same issue here

I have started seeing this tonight.

Could it be some kind of rate limit as I have been doing some heavy testing with TTS.

Same issue with all of Apple TV device

I am also running into this issue. I can pause/play whatever is currently playing on the apple tv from my home assistant setup, but as soon as I try streaming media from home assistant I get the same error. Has anyone been able to figure out how to resolve this?

I removed the Apple TV integration and added it again. Then it works again.

I also have this same issue.

What I have tried:

  • Delete all Apple Home setup and recreate
  • Reset all HomePods (Original Model) and all have latest firmware and then added to Apple HomeKit
  • Removed AppleTV from Home Assistant and Re-added Add-On
  • Add HomePod via IP instead of name.

My HA is very basic with only Z2M running and HACS with a small amount of extra layout cards.

This issue of Failed to call service media_player/play_media. already streaming to device happened occasionally when before I upgraded to HA 2024.1.2 but now it happens all the time since upgrading.

Is there anything else that I should be doing?

Similar issue here (HA 2024.1.5), when I want to play a stream on Apple TV (Apple TV 4K [1G, 64GB], TVOs 17.2) it only works randomly one out of ten times:

service: media_player.play_media
target:
  entity_id:
    - media_player.living_room
data:
  media_content_id: https://edge56.live-sm.absolutradio.de/absolut-relax/stream/mp3
  media_content_type: audio/mp3

Error message comes up:

The log shows the following:

Content of log:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/apple_tv/media_player.py:303
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 08:43:19 (1 occurrences)
Last logged: 08:43:19

[546000969152] Error handling message: Unknown error (unknown_error) XXX from 192.168.188.52 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Iron Safari/537.36)
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/websocket_api/commands.py", line 782, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 1587, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 426, in async_run
    await self._async_step(log_exceptions=False)
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 479, in _async_step
    self._handle_exception(
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 502, in _handle_exception
    raise exception
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 476, in _async_step
    await getattr(self, handler)()
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 713, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 675, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/core.py", line 2173, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/core.py", line 2210, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/apple_tv/media_player.py", line 303, in async_play_media
    await self.atv.stream.play_url(media_id)
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/core/facade.py", line 356, in play_url
    await self.relay("play_url")(url, **kwargs)
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/protocols/airplay/__init__.py", line 124, in play_url
    takeover_release = self.core.takeover(RemoteControl)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/core/facade.py", line 744, in takeover
    relayer.takeover(protocol)
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/core/relayer.py", line 119, in takeover
    raise exceptions.InvalidStateError(
pyatv.exceptions.InvalidStateError: Protocol.AirPlay has already done takeover

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:476
First occurred: 08:43:19 (1 occurrences)
Last logged: 08:43:19

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Protocol.AirPlay has already done takeover
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 476, in _async_step
    await getattr(self, handler)()
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 713, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/script.py", line 675, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/core.py", line 2173, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/core.py", line 2210, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/entity_component.py", line 272, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/homeassistant/components/apple_tv/media_player.py", line 303, in async_play_media
    await self.atv.stream.play_url(media_id)
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/core/facade.py", line 356, in play_url
    await self.relay("play_url")(url, **kwargs)
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/protocols/airplay/__init__.py", line 124, in play_url
    takeover_release = self.core.takeover(RemoteControl)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/core/facade.py", line 744, in takeover
    relayer.takeover(protocol)
  File "/srv/homeassistant/lib/python3.11/site-packages/pyatv/core/relayer.py", line 119, in takeover
    raise exceptions.InvalidStateError(
pyatv.exceptions.InvalidStateError: Protocol.AirPlay has already done takeover

Same here, from 2024.3 release, all of my homepods went unreliable, sometimes dropping already streaming error, or just simply not playing sounds.
Integration should be reloaded, it helps for a while, but after 1-2 hours (or an unknow reason) it fails again.

Will try to remove and re-add them, hope it helps.