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

Apple TV Integration - Artwork and Title doesnt work by APP change #1900

Open
pimp1310 opened this issue Jan 7, 2023 · 16 comments
Open

Apple TV Integration - Artwork and Title doesnt work by APP change #1900

pimp1310 opened this issue Jan 7, 2023 · 16 comments
Labels

Comments

@pimp1310
Copy link

pimp1310 commented Jan 7, 2023

Describe the bug

When i change the title for example in Netflix on the AppleTV 4K with TVos 16.2 the artwork picture and title sometimes work, but when i change to another title Movie or Tvshow Episode on antoher App (example Amazon Prime) the artwork and title is empty, he only shows the name of the App, example (Netflix or Amazon Prime)

Or when you play something in Netflix and get all media and than change to amazon video, the title and Artwork is empty!

When i reload the integration, the Artwork and title works well.

Error log

home-assistant_apple_tv_2023-01-07T08-25-22.000Z.log

How to reproduce the bug?

Easy change from the App Netflix to antoher App an play something

What is expected behavior?

that he refreshes the artwork and Title

Operating System

Home Assistant 2023.1.1

Python

3.6

pyatv

i dont know where to find, but i use the hacs addon version 3.0.1

Device

Apple TV 4K 2021 TvOs 16.2 and Apple TV 4K 2017 TvOS 16.2

Additional context

I Provided a Log, where i startet at netflix than changed to Amazon Video and back to Netflix and i played everytime something

when i reload the integration it works well, you can test it with

service: homeassistant.reload_config_entry data: {} target: entity_id: media_player.wohnzimmer

@pimp1310 pimp1310 added the bug label Jan 7, 2023
@mschwartz
Copy link

Same here.

I have modified my application to exit and restart any time the device state changes (idle, playing, paused). This causes a lag while the app scans for Apple TVs (I have four) and connects to each. But it’s better than having wrong information displayed in my app.

Even when the Apple TV is powered off, pyatv is telling me the device is powered on and the last thing played is the metadata returned and state is paused.

I f I pause a program, but not YouTube video, pyatv tells me that the position is advancing as if playing. If I scrub to a random position, it’s way off.

I found this on Apple’s site (somewhat related, and interesting all the same):
https://tvpartners.apple.com/support/3669-metadata-requirements

@postlund
Copy link
Owner

From what I can see in the log, you are seeing expected behavior. The amazon app does not seem to provide any artwork (search for artworkAvailable in the log). The title is also set to "" at some point. What I recommend is trying the same thing and comparing result with pyatv and an iOS device. If it is working in iOS, then it's a bug in pyatv. Otherwise it's likely a tvOS bug or an app that does not provide expected metadata.

@mschwartz
Copy link

I see title and artwork…
image

@postlund
Copy link
Owner

@mschwartz Can you still reproduce this with some logs so I can have another look?

@mschwartz
Copy link

mschwartz commented May 29, 2023

I think it’s easy to reproduce using your command line tool.

As you are receiving the push messages, all you need to do is pause the Apple TV for 5 seconds. When you resume, the playback position will be 5 seconds ahead instead of where it was when you paused.

It’s really obvious if you scrub the playback (fast forward) and push play. The playback position will be way off.

if it works during push, then it may be that I am polling for status 1/sec and the polled routines in pyatv aren’t working right.

@mschwartz
Copy link

The title and artwork are fine. Though it isn’t returning idle if I go to the Home Screen while playing.

@postlund
Copy link
Owner

Yeah, I think I can see it now:

  Media type: Unknown
Device state: Playing
       Title: Peppa konstnären | Greta Gris | Tecknat för barn | WildBrain Svenska
      Artist: WildBrain Svenska
       Album:
    Position: 197/1881s (10.5%)
      Repeat: Off
     Shuffle: Off
--------------------
  Media type: Unknown
Device state: Paused
       Title: Peppa konstnären | Greta Gris | Tecknat för barn | WildBrain Svenska
      Artist: WildBrain Svenska
       Album:
    Position: 565/1881s (30.0%)
      Repeat: Off
     Shuffle: Off

In my case however, the reason for this is my system time not being synced properly (it was about 6min off). After doing an NTP-sync, it works as expected again:

  Media type: Unknown
Device state: Paused
       Title: Peppa konstnären | Greta Gris | Tecknat för barn | WildBrain Svenska
      Artist: WildBrain Svenska
       Album:
    Position: 567/1881s (30.1%)
      Repeat: Off
     Shuffle: Off
--------------------
  Media type: Unknown
Device state: Playing
       Title: Peppa konstnären | Greta Gris | Tecknat för barn | WildBrain Svenska
      Artist: WildBrain Svenska
       Album:
    Position: 568/1881s (30.2%)
      Repeat: Off
     Shuffle: Off
--------------------
  Media type: Unknown
Device state: Paused
       Title: Peppa konstnären | Greta Gris | Tecknat för barn | WildBrain Svenska
      Artist: WildBrain Svenska
       Album:
    Position: 569/1881s (30.2%)
      Repeat: Off
     Shuffle: Off
--------------------

The Apple TV sends timestamps that are compared with the time locally, so both systems must be in sync. Is that the case for you?

I however believe we are not dealing with the initial issue anymore... Should maybe get back to that.

@mschwartz
Copy link

mschwartz commented May 29, 2023

All my systems, iPads, etc. are ntp time synchronized.

The problem is after you pause, say for 5 seconds, and resume, the playback position is 5 seconds in the future.

@postlund
Copy link
Owner

Oh, I can see now that you are using the beta version from HACS @pimp1310 . That version is really, really old. You should remove the integration and use the version bundled with Home Assistant. A lot has happened since then.

@postlund
Copy link
Owner

@mschwartz I don't see that issue with atvremote, but I have an idea. The media_position_updated_at attribute should return the time when play/pause state was "activated". It just returns current time right now, so it is possible that other state changes trigger position updates that shouldn't happen. Can you make some manual changes to try my hypothesis?

@mschwartz
Copy link

mschwartz commented May 30, 2023

👍 absolutely!

I think at remote uses a push api? I’m polling once per second, not using the push API.

@mschwartz
Copy link

mschwartz commented May 30, 2023

@postlund I would be happy to share my python code here. I am not a python expert by any stretch. Maybe I am doing something foolish or wrong.
Archive.zip

2 files. One is 149 lines, the other is 263. Not much to see :)

I would love to see this kind of thing added to pyatv as well. Just like you have the command line tool, a pyatv<->MQTT bridge might be very useful to people.

@postlund
Copy link
Owner

Gah, I'm just mixing things up... I have now tried to reproduce this with the YouTube app (polling, no push). Basically what I have done is:

  • Started a video
  • Checked position
  • Paused and waited for a while
  • Checked position a few time (it matches what is played)
  • Started to play again
  • Checked position (correct with playback)
  • Paused and scrubbed
  • Re-checked in the same way as above: everything looks ok

Is that correct? Does this happen for all apps?

@mschwartz
Copy link

mschwartz commented May 31, 2023

/Actually, I think YouTube is the only one that works. We watch a lot of shows and movies using the computers app. Playing from a library on a Mac computer.

I really do appreciate the help and time you’ve putting into this.

what I’ve done I the code I attached above is to exit the program when deviceState changes. It’s automatically restarted by a sh script that runs the program in a loop. In a Docker container. Restart does get the time in sync.

If you scrub the video, push select then gesture left or right, it’s really way out of sync.

@mschwartz
Copy link

Also, I have 4x Apple TVs connected at the same time. Is it possible this is something causing the error?

@postlund
Copy link
Owner

I will try to find some time to test this out a bit more and also look at your code. I'll let you know if I make some progress. I don't think the amount of Apple TVs should be any problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

No branches or pull requests

3 participants