Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Chromecast YouTube video from my Android app

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.

like image 321
joaomgcd Avatar asked Aug 07 '13 23:08

joaomgcd


2 Answers

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.

like image 87
Leon Nicholls Avatar answered Oct 05 '22 23:10

Leon Nicholls


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.

like image 39
Sreedhar Perim Avatar answered Oct 05 '22 23:10

Sreedhar Perim