postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
841 stars 91 forks source link

Question about ATV and AirPlay 1 vs 2 #2135

Open philippe44 opened 10 months ago

philippe44 commented 10 months ago

What do you need help with?

Hi - I'm the author of a few apps that use AIrPlay and we talked a bit in the past. I'm facing an issue for which you might have a better insight. When used with AirPlay 1, AppleTV, seems to very often fail to display any metadata (text & artwork). They display "nothing playing" and when in that state, most of the time a restart is required for them to display metadata again. Restarting my control app does not change anything, only restarting the AppleTV works. It's strange as well because the artwork is often on track behind, although what is being sent is correct (verified using wireshark). Any hint?

Thanks!

postlund commented 10 months ago

Hey! I haven't experienced this exact behavior per se, but I (and many other users) typically see something similar when using play_url to play a video. For some reason something in the Apple TV breaks completely and metadata stops working altogether. My Implementation of said function was broken for a long time, so that was likely part of it but I would expect the Apple TV to recover without a restart at some point. That said... As I fixed play_url recently that should not be as problem anymore though.

Just to clarify here, are you only using pyatv or do you see the same behavior from iOS or other senders too?

philippe44 commented 10 months ago

Thanks for answering! I see that behavior with my own senders and I'm looking for a way to fix or reduce it. Could you share what you did to improve the issue?

postlund commented 10 months ago

It is probably possible with AirPlay 1 somehow, but I focused on AirPlay 2 (I kept the previous implementation based on v1 for older devices). The main thing I changed was to set up an AirPlay 2 session and adding a few additional fields when starting the stream. Bear in mind that this only matters when playing video or audio using the /play endpoint, thus not RTP streaming. Just want to make that clear. Just calling /play without setting up a session (and sending keep-alive) will break things as discussed earlier.

All the changes I made are in this PR: https://github.com/postlund/pyatv/pull/2079

It can also be helpful looking at the traffic with --debug if you are using atvremote.

If you want any more specific help (like content of messages, etc) please let me know and I'll try to explain if I can.

philippe44 commented 10 months ago

Is there a way now for force play_url to use version 1? Sorry I did not see it

postlund commented 10 months ago

You can modify the source here to always return the v1 Implementation:

https://github.com/postlund/pyatv/blob/6438d9f8e1daca138164f2c3e543487d45d03d54/pyatv/protocols/airplay/__init__.py#L167

There's currently no other way than modifying the source unfortunately. At some point when I have implanted the storage API, I might as settings to allow things like these to be manageable in runtime.

philippe44 commented 10 months ago

I've tried that but playback fails then (connection lost). Well, I guess I won't get that to work. Thanks anyway!

postlund commented 10 months ago

Can you provide some logs? Maybe I can find something.