Madu
Madu

Reputation: 5019

YTPlayerView thumbnail custom size

I am using YTPlayerView library from Google. I want to get the customised size thumbnail of a youtube video for my iOS app.

Can anybody help me how I can achieve this? Current it is giving me the same size thumbnail for a video regardless of the size of my YTPlayerView.

Upvotes: 2

Views: 530

Answers (1)

Abhishek
Abhishek

Reputation: 1261

YTPlayerView.load automatically loads its own thumbnail. However, a workaround could be you place a UIImageView on top of the YTPlayerview. And load the customized thumbnail into that UIImageview. You can start playing the video when the UIImageview is clicked using YTplayerview.play. And then hide the thumbnail. In essence, it would give the effect the video is being played upon clicking your customised thumbnail image. You may have to fine-tune some things to make this solution work elegantly.

To retrieve the image for the customised thumbnail, you can use any of 4 generated images of youtube. They are predictably formatted as follows:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
https://img.youtube.com/vi/<insert-youtube-video-id-here>/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:

https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg

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

https://img.youtube.com/vi/<insert-youtube-video-id-here>/hqdefault.jpg

I hope this helps to answer your question.

Upvotes: 0

Related Questions