-2

I have some YouTube links and I want to make a list like the playlist that exists in youtube such that a screen shot from the video automatically appear and when the user click on the link it opens the youtube app How can I do it ?

thanks in advance

  • 1
    look into YouTube API for getting screenshots, and firing intents in Android Developer guides to launch another application. – Madushan Jul 23 '16 at 09:48

1 Answers1

1

For the YouTube thumbnails, you can use the techniques outlined in this answer to grab the url of several auto-generated thumbnails, and using an image library like Picasso it is straightforward to load the image into an ImageView:

private static final String EXAMPLE_YOUTUBE_VIDEO_ID = fMOqfsBzqLU;

public static String getYouTubeThumbnailUrl(String videoId) {
    return "http://img.youtube.com/vi/" + videoId + "/0.jpg";
}

//To use...

Picasso.with(context).load(getYouTubeThumbnailUrl(EXAMPLE_YOUTUBE_VIDEO_ID)).into(imageView);

Use a RecyclerView or ListView to display the images, and set an onClickListener() to the ImageView that links to the video on YouTube:

public static String getYouTubeVideoLink(String videoId) {
    return "https://www.youtube.com/watch?v=" + videoId;
}

//To launch the video in the defaul browser...

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(getYouTubeVideoLink(EXAMPLE_YOUTUBE_VIDEO_ID)));
startActivity(i);

Edit: To open the video in the YouTube app, you can use try the examples in this post, or explore the YouTubePlayer API.

Community
  • 1
  • 1
PPartisan
  • 8,173
  • 4
  • 29
  • 48