plex_assistant icon indicating copy to clipboard operation
plex_assistant copied to clipboard

Shield play command results in playback in background of Shield Plex Client menus

Open OmniDefenestrator opened this issue 5 years ago • 17 comments

Setup: HomeAssistant on Ubuntu with HACS-installed plex-assistant and IFTTT hook, pointing to the latest Nvidia Shield TV Pro as the default plex player.

Errors in plex-assistant or plex-server: none

Problematic commands: seemingly any playback commands, but I can reproduce reliably with "play a random episode of seinfeld" and "play better off ted"

Advanced/custom config: none, just a vanilla HACS install using the Shield as my "default plex player"

Steps to reproduce:

  1. Using a Google Home, say the command "Hey Google, tell plex to play a random episode of seinfeld". ("tell plex" is my IFTTT hotword hook).
  2. Assistant will verify the IFTTT call, IFTTT will proxy to plex-assistant/plex, and playback will start of the requested media on the Shield with the video properly in the foreground.

Expected: The video continues playing in the foreground

Actual: After about 1-2 seconds, the Shield's Plex client browse menu (i.e. where you'd go to select the media to play from the TV) comes back up, and covers the entire screen. However, the video's audio is continuing in the background, so the media is still playing in the background. There's no way to close or exit the menu to return to the playback. This does not happen on other plex clients (specifically tested on Rasplex, which correctly plays and keeps the video in the foreground). Strangely enough, there doesn't seem to be a way to have any sort of background playing happen on the Shield through its official interface, so maybe there's some unexpected API calls being made by plex-assistant? The playback also works correctly if I choose the Shield as the cast target from app.plex.tv's web UI (i.e. not using plex-assistant).

OmniDefenestrator avatar Apr 12 '21 07:04 OmniDefenestrator

Important:

Issues that don't provide the information requested in the troubleshooting docs may not get a reply and may be closed until the info is provided. Please, include as much of the requested info as possible so that I can replicate and investigate your issue.

When pasting in your config/code/errors always place 3 backticks ``` above the first line and after the last line. Doing this will format it correctly.

github-actions[bot] avatar Apr 12 '21 07:04 github-actions[bot]

Couple of questions:

  • Are you using a startup script for the device?
  • Does this happen when using the Home Assistant service play_media?

You can test it in developer tools. Example:

service: media_player.play_media
target:
  entity_id: media_player.shields_entity_id
data:
  media_content_type: movie
  media_content_id: 'plex://{"library_name": "Movies", "title": "Groundhog Day"}'

maykar avatar Apr 17 '21 11:04 maykar

Are you using a startup script for the device?

The Shield does not have a startup script, I turn that on manually. Plex Media Server (on a standalone linux box) starts up with systemd. HomeAssistant is running in a docker container with a restart always policy on the same machine as PMS.

Does this happen when using the Home Assistant service play_media?

The issue does not reproduce with a devtools Home Assistant service call. Specifically, the media starts playing correctly and remains in the foreground, as expected. I had to make some minor tweaks to the command to get it to parse, which I've listed below (specifically, I had to remove the plex:// intent prefix to get it to parse as JSON.

service: media_player.play_media
target:
  entity_id: media_player.plex_plex_for_android_tv_shield_android_tv
data:
  media_content_type: movie
  media_content_id: "{\"library_name\": \"Movies\", \"title\": \"Pitch Perfect\"}"

Please let me know if there's any additional information you need. Thanks!

I'll see if I can get Shield network logs for the homeassistant API vs plexassistant, maybe that'll shed some light on what might be going on.

OmniDefenestrator avatar Apr 17 '21 12:04 OmniDefenestrator

OK, grabbed some logs from Shield.

Steps:

  1. Enable network logging on Shield
  2. Open network logging page.
  3. Give command to start playback (either "hey google, play pitch perfect 3" for plex-assistant trigger or homeassistant dev tools command pasted above).
  4. Refresh logs page after video has been playing for a few seconds (plex-assistant triggered playback has already returned to home screen with audio continuing in background at that point).

Home Assistant Dev API playback Shield logs (working): https://pastebin.com/4mvTKrKk plex-assistant playback Shield logs (broken): https://pastebin.com/AGWPwrjz

OmniDefenestrator avatar Apr 17 '21 13:04 OmniDefenestrator

Interesting, will look into it further, but all Plex Assistant is doing is calling the same service as above.

maykar avatar Apr 17 '21 13:04 maykar

Is the shield entity. media_player.plex_plex_for_android_tv_shield_android_tv, the same entity you are using for Plex Assistant and not something like media_player.shield?

maykar avatar Apr 18 '21 13:04 maykar

Is there a place I can verify that? I don't see it in the HomeAssistant -> Configuration -> PlexAssistant Options screen, nor did I see anything useful in /custom_components.

I deleted and readded PlexAssistant (via HACS again) and explicitly set my default cast device as the Shield, and the same issue happens. I'm hoping setting the default device correctly sets the entity?

OmniDefenestrator avatar Apr 18 '21 21:04 OmniDefenestrator

Well, the shield device can show up as two separate devices (one from the device itself and one from the plex integration) which is why I ask. Can you enable Plex Assistant's debug logs as explained in the troubleshooting guide, make a call to play something, and post the debug lines here?

maykar avatar Apr 18 '21 21:04 maykar

2021-04-18 14:58:05 DEBUG (SyncWorker_1) [custom_components.plex_assistant.const] Media titles: 12163
2021-04-18 15:00:09 DEBUG (SyncWorker_0) [custom_components.plex_assistant.const] IFTTT Call: play Pitch Perfect 3
2021-04-18 15:00:09 DEBUG (SyncWorker_5) [custom_components.plex_assistant.const] Command: play Pitch Perfect 3
2021-04-18 15:00:09 DEBUG (SyncWorker_5) [custom_components.plex_assistant.const] Processed Command: {'media': 'pitch perfect 3', 'device': 'Plex (Plex for Android (TV) - SHIELD Android TV)'}
2021-04-18 15:00:09 DEBUG (SyncWorker_2) [custom_components.plex_assistant.const] Command: play Pitch Perfect 3
2021-04-18 15:00:09 DEBUG (SyncWorker_2) [custom_components.plex_assistant.const] Processed Command: {'media': 'pitch perfect 3', 'device': 'Plex (Plex for Android (TV) - SHIELD Android TV)'}
2021-04-18 15:00:27 DEBUG (SyncWorker_5) [custom_components.plex_assistant.const] Updated Library: 2021-04-18 15:00:27.390957
2021-04-18 15:00:27 DEBUG (SyncWorker_5) [custom_components.plex_assistant.const] PA Devices: {'Plex (Plex for Android (TV) - SHIELD Android TV)': {'entity_id': 'media_player.plex_plex_for_android_tv_shield_android_tv', 'device_type': 'plex'}, 'SHIELD': {'entity_id': 'media_player.shield_2', 'device_type': 'cast'}, 'Living Room TV': {'entity_id': 'media_player.chromecastultra5142', 'device_type': 'cast'}, 'Office display': {'entity_id': 'media_player.nesthubmax59f3', 'device_type': 'cast'}, 'Living Room speaker': {'entity_id': 'media_player.living_room_speaker', 'device_type': 'cast'}}
2021-04-18 15:00:27 DEBUG (SyncWorker_5) [custom_components.plex_assistant.const] Device: Plex (Plex for Android (TV) - SHIELD Android TV)
2021-04-18 15:00:27 DEBUG (SyncWorker_5) [custom_components.plex_assistant.const] Media: [<Movie:1150:Pitch-Perfect-3>]
2021-04-18 15:00:30 DEBUG (SyncWorker_2) [custom_components.plex_assistant.const] Updated Library: 2021-04-18 15:00:30.403895
2021-04-18 15:00:30 DEBUG (SyncWorker_2) [custom_components.plex_assistant.const] PA Devices: {'Plex (Plex for Android (TV) - SHIELD Android TV)': {'entity_id': 'media_player.plex_plex_for_android_tv_shield_android_tv', 'device_type': 'plex'}, 'SHIELD': {'entity_id': 'media_player.shield_2', 'device_type': 'cast'}, 'Living Room TV': {'entity_id': 'media_player.chromecastultra5142', 'device_type': 'cast'}, 'Office display': {'entity_id': 'media_player.nesthubmax59f3', 'device_type': 'cast'}, 'Living Room speaker': {'entity_id': 'media_player.living_room_speaker', 'device_type': 'cast'}}
2021-04-18 15:00:30 DEBUG (SyncWorker_2) [custom_components.plex_assistant.const] Device: Plex (Plex for Android (TV) - SHIELD Android TV)
2021-04-18 15:00:30 DEBUG (SyncWorker_2) [custom_components.plex_assistant.const] Media: [<Movie:1150:Pitch-Perfect-3>]

OmniDefenestrator avatar Apr 18 '21 22:04 OmniDefenestrator

Yup, 2 different entities for the same device:

  • media_player.plex_plex_for_android_tv_shield_android_tv
  • media_player.shield_2

Try this in developer tools and let me know if you see the same behavior of background playing:

service: media_player.play_media
target:
  entity_id: media_player.shield_2
data:
  media_content_type: movie
  media_content_id: "plex://{'library_name': 'Movies', 'title': 'Pitch Perfect'}"

maykar avatar Apr 18 '21 22:04 maykar

Using media_player.shield_2 made the Shield switch to internal-Chromecast mode (it didn't play, but the screen is now just a chromecast icon). I can probably just disable the internal chromecast, as I have a standalone real chromecast already.

OmniDefenestrator avatar Apr 18 '21 22:04 OmniDefenestrator

Nah, I wouldn't do all that. Just set the Plex (Plex for Android (TV) - SHIELD Android TV) as your default device instead of the one called "SHIELD" which is media_player.shield_2 and see if it helps the situation.

If that works out and you want the Sheild as you default device, then you're done. Otherwise, make sure Plex (Plex for Android (TV) - SHIELD Android TV) is available, then change the friendly name of "SHIELD" (AKA media_player.shield_2) to something else and make the Plex SHEILD Andriod TV friendly name shield.

maykar avatar Apr 18 '21 22:04 maykar

Plex (Plex for Android (TV) - SHIELD Android TV) is the one that I've been setting to default, and (unless I'm reading the debug logs incorrectly), it's also the one that plexassistant is (correctly) choosing for playback.

OmniDefenestrator avatar Apr 18 '21 22:04 OmniDefenestrator

My mistake, then I would try it the other way around and see if it helps. Set media_player.shield_2 (aka "SHEILD") to the default device and see if the behavior is the same.

And if that works, just change the friendly name of Plex (Plex for Android (TV) - SHIELD Android TV) to something that doesn't include the word "shield"

You don't need to uninstall from HACS, just remove it from the integrations page and add it again.

maykar avatar Apr 18 '21 22:04 maykar

Hmm, it looks like using media_player.shield_2 in plex-assistant results in nothing playing (I get a plex screen saying "sorry something went wrong"). The plexassistant debug logs look correct though (no unexpected errors).

My guess is that media_player.shield_2 is the Shield's internal Chromecast which doesn't seem to play nice with plex playback for some reason (the homeassistant devtools didn't work for it either), and Plex (Plex for Android (TV) - SHIELD Android TV) is the direct intent into casting inside of the Shield's Plex Client app (which worked correctly from devtools, and starts playback in foreground and immediately goes to background for plexassistant - i.e. broken).

OmniDefenestrator avatar Apr 18 '21 22:04 OmniDefenestrator

I'll try poking around in the src of my local install to see if I can debug any further. Do I need to do anything special (rebuild/etc), or is just modifying .py files and restarting homeassistant sufficient? Do you have any codepointers I should specifically be starting wwith/looking at? I don't have experience with homeassistant specifically, but I'm familiar enough with Python.

OmniDefenestrator avatar Apr 18 '21 23:04 OmniDefenestrator

OK looks like I somehow had a double installation of plex_assistant, possibly from a bugged manual upgrade to v1.0. I noticed there were double the logs from plex_assistant for a single command (as seen in my debug logs posted above). I fully removed any existing plex_assistant entries from the HA UI, manually deleted all directories/files I found on my filesystem, and readded the repository via HACS. I also had some old directives in HA's configuration.yaml for the old plex_assistant which I also deleted. I then reinstalled the integration fresh, restarted HA, and it seems to work correctly now! The debug logs for plex_assistant now also only show one "Processed Command" entry rather than two. I'm guessing there was some race condition in how Shield was handling back to back queue playback commands, and the double-command-processing was causing the issue.

Sorry for the noise, but thanks for your help in debugging!

OmniDefenestrator avatar Apr 19 '21 03:04 OmniDefenestrator