i8beef / node-red-contrib-castv2

MIT License
22 stars 15 forks source link

Youtube Cast to Google Home devices #35

Closed Steve2955 closed 3 years ago

Steve2955 commented 3 years ago

I would love to cast the audio of a youtube video to one of my Google Home Minis, but unfortunately I'm getting an error every single time.

"TypeError: Cannot read property 'then' of undefined"

Sadly I could not get any more information out of the node-red logs. The TTS-Action works fine and Youtube Cast to a Chromecast works great as well. Do you know what's the issue here? Is it possible to get an audio-only cast from Youtube to a Google Home device? Thank you very much in advance.

i8beef commented 3 years ago

Based on this: https://support.google.com/googlenest/thread/17735428?hl=en

It doesn't appear you can cast video content to non-video Google Home devices. Have you tried your specified video against a video device?

I will take a look and see if I can replicate on my side though, as there should probably be a check where ever you are getting that. Can you send me your actual message that you are sending into it? I see a possible place this could happen, but only if you failed to pass a videoId on the message...

Steve2955 commented 3 years ago

That's to payload I've been sending to my Google Home:

return {
  payload: {
    app: "YouTube",
    type: "MEDIA",
    videoId: "L_jWHffIx5E"
  }
};

When I just tried it again, the error message didn't show up like before. This time the Google Home did it's pairing beep, but still didn't play the audio from the Youtube cast. In the Google Home App it's shown that my Google Home is receiving a stream and that it's playing. I'm unable to pause the stream and it's not actually playing anything. I can only stop streaming within the app. Casting to my Chromecast still works fine with to payload above.

EDIT: Below is the status I get back from your node when casting to the Google Home. It shows up a few times in the debug console, but the content is always the same. It never goes to the BUFFERING or PLAYING state like my Chromecast.

{
  "mediaSessionId":1149706518,
  "playbackRate":1,
  "supportedMediaCommands":262147,
  "volume":{
    "level":0.3799999952316284,
    "muted":false},
   "playerState":"IDLE",
   "customData":{
    "playerState":-1
  }
}
i8beef commented 3 years ago

I just pushed a new version that should at least deal with this a little more gracefully. While the Cast framework on the Google Home mini will allow the YouTube app to launch (the beep you hear), it explicitly rejects video content, but not in a way that I seem to be able to pick up from the underlying library. Before that would leave you in two weird places:

  1. If you failed to pass a video id it recognized, it would end up with your original error where a Promise wouldn't be returned correctly. That's been corrected so it will at least throw an error in this case that the app can react to.
  2. It would start the app, but if you tried to run any other command (TTS, media cast, etc.) it wouldn't realize the app it needed isn't actually currently running, and would likely fail to handle the command as it would be trying to execute, say, a DefaultMediaReceiver command in the YouTube app controller. It will now detect that the current session app isn't the one it should be targeting and trigger a launch of the right app first.

This doesn't really solve your issue, sorry about that, it just appears Google doesn't support what you want to do... but thank you for reporting this as it pointed out a hole in the handling of multiple apps.

Steve2955 commented 3 years ago

Thank you very much for your work. So without some action at Google's end it's not possible to cast Youtube Videos directly to a Google Home. Personaly, I will have to build some workaround using youtube-dl and the DefaultMediaReceiver, which should work fine for my intended use, but is definitly not suitable for dynamically casting Youtube videos to a Google Home.

A last thing I would like to point out is that when using Chrome on your PC you can cast Youtube to a Google Home device and it will only play the audio stream. The video stream is still shown on your PC (unlike when casting to a chromecast), but when closing the Youtube page the audio stops playing as well. I don't know how this works but since it seems like an active redirect of the stream so it's probably not suitable for implementation in this project.

i8beef commented 3 years ago

Yeah it looks like the YouTube app is smart enough to cast the TAB to the target in the browser case, something which this node cannot do.