Friday, June 29, 2012

Android and YouTube

One of my application requires playing YouTube Videos. As always I was probing for the query. And I got a very nice solution and also got to know an interesting fact about how we can extract you tube thumbnail URL from the Video URL.


To play a you tube Video from your application first of all you need the YouTube Video ID which you can easily get from the YouTube Video URL.


For Example you have YouTube URL


http://www.youtube.com/watch?v=aIqzxU6mG8M


Here you have a video ID v = alqzxU6mG8M


So you just need to pass this Video ID to the intent and it will play the video.

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + "aIqzxU6mG8M"));
startActivity(intent);

Now lets see how we can get the YouTube Video thumbnail from this Video ID




You just need to substitute the Video ID to the above URL.

0.jpg is a full sized image. The other two are very small and are taken automatically by YouTube from two certain points in the video.

No comments:

Post a Comment