Open Chromecast YouTube video from my Android app

爷,独闯天下 提交于 2019-11-28 19:54:40

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!