I am currently developing an application that requires playing YouTube videos in full screen mode. After scraping around and putting together the pieces, I currently have the following code which I hope is of use to anybody else out there.
public void playYouTubeVideo(String videoId) { String videoTemplate = "@YTBASE@@VIDEO@"; String videoAction = videoTemplate .replace("@YTBASE@", "vnd.youtube://") .replace("@VIDEO@", videoId); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(videoAction)); intent.putExtra("VIDEO_ID", videoAction); intent.putExtra("force_fullscreen", true); startActivity(intent); }
There are some points to bear in mind though...
- Once the ACTION_VIEW intent has control, your application is effectively paused i.e. it won't work until you use the back button to exit the player intent and return to your application.
- It may or may not work in the future of YT change the way they operate, but that's always the case.
Point 2 is the reason I have used the variables videoTemplate and the @ delimited markers... hopefully you can see what's going on there and change it in the future if you need to.
I now realise that I may well have to use the "official" YouTube API and create an application API key and all the rest of it but if it means seamless integration then I will do just that but I thought I'd at least share what I had so far.
I now realise that I may well have to use the "official" YouTube API and create an application API key and all the rest of it but if it means seamless integration then I will do just that but I thought I'd at least share what I had so far.
So, I hope the above serves useful to you. Back to the hack...
Comments
Post a Comment