8

I'm able to use my own whitelisted url for feeding my chromecast videos, but can I make it stream a YouTube video directly from my app?

I assume all I would need is to launch the YouTube app remotely and feed it a video ID somehow, but I can't find out how to do that.

Has anyone done this from an Android app?

Thanks.

jbowes
  • 4,062
  • 22
  • 38
joaomgcd
  • 5,287
  • 4
  • 28
  • 39

2 Answers2

9

I suspect Google would want you to launch the YouTube app locally on the mobile device and then let the user cast the video to the ChromeCast device.

However, if you want to hack another solution, here is another option:

To view a YouTube video on your ChromeCast device you need to load a URL like this on the device: https://www.youtube.com/tv?v=g1LsT1PVjUA

This will display the TV version of the YouTube player. Now you have to find a way for your receiver HTML page to redirect to that page. This can be done with some Javascript in your receiver page. The URL could be passed to the receiver from you mobile app by using your own protocol. Look at the Cast SDK tic-tac-toe example on how to make your own protocol.

So your mobile app will launch your receiver, then you will pass the video id to your receiver over the web socket connection created by the Cast SDK. The receiver HTML will then grab the id and then use "window.location.href" to load the YouTube video URL.

Leon Nicholls
  • 4,623
  • 2
  • 16
  • 17
  • Thanks for the workaround. I'll try and see how that looks. But do you think there's a way to launch the youtube "app" on the Chromecast and pass it the right parameters so it opens a video in the app directly? – joaomgcd Aug 08 '13 at 14:56
  • 1
    Google hasn't documented that for developers. So I assume they want the user to do that through their own YouTube app. – Leon Nicholls Aug 08 '13 at 15:39
  • 1
    This works. I created a custom receiver. And from my IOS Swift app I send a message with the video id to the receiver app. Then in the receiver app I open it using `window.location.href` – A.W. Dec 01 '14 at 09:30
  • I tried this again on 2 chromecast devices and now when loading a youtube video this way the chromecast only displays the youtube logo on screen with the audio of the video but there is no video playing. Anyone has this? – A.W. Dec 26 '14 at 18:18
6

Not sure if you are still looking for a solution for this. The way to do it is as follows:

MimeData data = new MimeData("v=g1LsT1PVjUA", MimeData.TYPE_TEXT);
mSession.startSession("YouTube", data);

The above should create a YouTube session and play the video.