How to display thumbnail of YouTube Videos in Android

前端 未结 5 2210
野的像风
野的像风 2020-12-07 23:42

I writing an app where i want to display a list of YouTube videos. But I want the list to display the video title with some other info but also show a thumbnail of the video

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 23:50

    With the Combination of Two Accepted Answer

    How to make YouTube video thumbnails in android?

    and

    How to get video thumbnail of youtube video in android list in android?

    Finally You just have to play with ID of YOUTUBE URL only.

    I found one PHP Answer for same question in that they have described like:

    Each YouTube video has 4 generated images. They are predictably formatted as follows:

    http://img.youtube.com/vi//0.jpg
    http://img.youtube.com/vi//1.jpg
    http://img.youtube.com/vi//2.jpg
    http://img.youtube.com/vi//3.jpg
    

    The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:

    http://img.youtube.com/vi//default.jpg
    

    For the high quality version of the thumbnail use a url similar to this:

    http://img.youtube.com/vi//hqdefault.jpg
    

    There is also a medium quality version of the thumbnail, using a url similar to the HQ:

    http://img.youtube.com/vi//mqdefault.jpg
    

    For the standard definition version of the thumbnail, use a url similar to this:

    http://img.youtube.com/vi//sddefault.jpg
    

    For the maximum resolution version of the thumbnail use a url similar to this:

    http://img.youtube.com/vi//maxresdefault.jpg
    

    All of the above urls are available over https too. Just change http to https in any of the above urls.

    Additionally, the slightly shorter hostname i3.ytimg.com works in place of img.youtube.com in the example urls above.

    Example:

    I have one URL https://www.youtube.com/watch?v=-OKrloDzGpU

    Now I will just take ID from URL i.e.: -OKrloDzGpU

    Medium Image: http://img.youtube.com/vi/-OKrloDzGpU/mqdefault.jpg

    HD Image: http://img.youtube.com/vi/-OKrloDzGpU/hqdefault.jpg

    Load Images in Android using Glide or Picasso:

    // Picasso        
    Picasso.with(context)
           .load("http://img.youtube.com/vi/-OKrloDzGpU/mqdefault.jpg")
           .into(imageView);
    
    // Glide
    Glide.with(this)
         .load("http://img.youtube.com/vi/-OKrloDzGpU/mqdefault.jpg")
         .into(imageView);
    

    Thank you. Hope it will helps you all.

提交回复
热议问题