Get / Make thumbnail image from video url getting in API response

Rohan

I am getting video URLs in the response from server (i.e from API not stored in local-device) as follwos ;

videos": [
    "<iframe width=\\"560\\" height=\\"315\\" src=\\"//www.youtube.com/embed/-OB7y6ELDks?list=UUYv2cbGZE2SmAYPDZQRKiig\\" frameborder=\\"0\\" allowfullscreen></iframe>",
    "<iframe width=\\"560\\" height=\\"315\\" src=\\"//www.youtube.com/embed/igcIaNi-eHA?list=UUYv2cbGZE2SmAYPDZQRKiig\\" frameborder=\\"0\\" allowfullscreen></iframe>",
    "<iframe width=\\"560\\" height=\\"315\\" src=\\"//www.youtube.com/embed/3kGNMUfajJc?list=UUYv2cbGZE2SmAYPDZQRKiig\\" frameborder=\\"0\\" allowfullscreen></iframe>"    
],

Currently it contains only youtube videos, but it is not sure, it may also contain url videos from other resources (i.e other than youtube).

I extracted youtube urls from this response. And want to display thumbnails of these videos in the UICollectionView.

How can i do this?

I searched a lot about this but could not get any proper solution.

Please help me.

Thanks..

Rohan

I have solved my problem using following code.

So I am attaching code here for others reference ;

-(void)setImage:(NSString*)urlResponse
{
    NSString *youtubeUrl = [NSString stringWithFormat:@"%@",[self parseVideoHTMLUrl: urlResponse]];

    NSString *videoThumbUrl = [self getYoutubeVideoThumbnail: youtubeUrl];

    NSURL* videoURL =[NSURL URLWithString:videoThumbUrl];

    [btn_photo sd_setImageWithURL:videoURL forState:UIControlStateNormal]; 
}

-(NSString *)parseVideoHTMLUrl:(NSString *)videoUrl
{
    NSRegularExpression *regex = [NSRegularExpression
                                  regularExpressionWithPattern:@";//(.+?)\\""
                                  options:NSRegularExpressionCaseInsensitive
                                  error:nil];
    NSTextCheckingResult *textCheckingResult = [regex firstMatchInString:videoUrl options:0 range:NSMakeRange(0, videoUrl.length)];

    NSString *url = [videoUrl substringWithRange:[textCheckingResult rangeAtIndex:1]];

    return url;
}

-(NSString*)getYoutubeVideoThumbnail:(NSString*)youTubeUrl
{
    NSString* video_id = @"";

    if (youTubeUrl.length > 0)
    {
        NSError *error = NULL;
        NSRegularExpression *regex =
        [NSRegularExpression regularExpressionWithPattern:@"(?<=watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*"
                                                  options:NSRegularExpressionCaseInsensitive
                                                    error:&error];
        NSTextCheckingResult *match = [regex firstMatchInString:youTubeUrl
                                                        options:0
                                                          range:NSMakeRange(0, [youTubeUrl length])];
        if (match)
        {
            NSRange videoIDRange = [match rangeAtIndex:0];
            video_id = [youTubeUrl substringWithRange:videoIDRange];

            NSLog(@"%@",video_id);
        }
    }

    NSString* thumbImageUrl = [NSString stringWithFormat:@"http://img.youtube.com/vi/%@/default.jpg",video_id];

    return thumbImageUrl;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to make thumbnail image from dailymotion video

From Dev

Android: json response, google api and getting image from url

From Dev

Video thumbnail image from directory

From Dev

Video thumbnail image from directory

From Dev

How to get thumbnail image of video picked from UIPickerViewController in Swift?

From Dev

How to get thumbnail image of video from ALAsset in iOS?

From Dev

How to Make MediaWiki Api call to get thumbnail image and title from coordinates

From Java

How do I get a YouTube video thumbnail from the YouTube API?

From Dev

Google images: get large image URL from thumbnail URL

From Dev

video thumbnail image not generated from local video URL(asset URL) iOS

From Dev

Getting thumbnail of a video picked from photos library

From Dev

If I want to get the thumbnail URL for a YouTube video, should I be using the "videos" API or the "thumbnails" API?

From Dev

Is it possible to Generate a thumbnail from a video url in android

From Dev

create thumbnail from video URL in C#

From Dev

acf, getting thumbnail size image from field

From Dev

How to Get Video Thumbnail from onActivityResult Intent?

From Dev

Get Video Thumbnail from specified postion - Android

From Dev

How to Get Video Thumbnail from onActivityResult Intent?

From Dev

How to get thumbnail for video from PHAsset?

From Dev

Make return URL for getting a response from bank/paymentgateway

From Dev

PHP - create thumbnail image from url

From Dev

how to create thumbnail image by using video url for jquery jplayer

From Dev

android: get thumbnail from blobstore image

From Dev

get Thumbnail image from wikimedia commons

From Dev

How to get image thumbnail from given link?

From Dev

Get an image from the video

From Dev

Youtube get image url from channel (not getting image)

From Dev

Getting a thumbnail of a *.mov video IOS

From Dev

Taking thumbnail image from video always returns null

Related Related

  1. 1

    How to make thumbnail image from dailymotion video

  2. 2

    Android: json response, google api and getting image from url

  3. 3

    Video thumbnail image from directory

  4. 4

    Video thumbnail image from directory

  5. 5

    How to get thumbnail image of video picked from UIPickerViewController in Swift?

  6. 6

    How to get thumbnail image of video from ALAsset in iOS?

  7. 7

    How to Make MediaWiki Api call to get thumbnail image and title from coordinates

  8. 8

    How do I get a YouTube video thumbnail from the YouTube API?

  9. 9

    Google images: get large image URL from thumbnail URL

  10. 10

    video thumbnail image not generated from local video URL(asset URL) iOS

  11. 11

    Getting thumbnail of a video picked from photos library

  12. 12

    If I want to get the thumbnail URL for a YouTube video, should I be using the "videos" API or the "thumbnails" API?

  13. 13

    Is it possible to Generate a thumbnail from a video url in android

  14. 14

    create thumbnail from video URL in C#

  15. 15

    acf, getting thumbnail size image from field

  16. 16

    How to Get Video Thumbnail from onActivityResult Intent?

  17. 17

    Get Video Thumbnail from specified postion - Android

  18. 18

    How to Get Video Thumbnail from onActivityResult Intent?

  19. 19

    How to get thumbnail for video from PHAsset?

  20. 20

    Make return URL for getting a response from bank/paymentgateway

  21. 21

    PHP - create thumbnail image from url

  22. 22

    how to create thumbnail image by using video url for jquery jplayer

  23. 23

    android: get thumbnail from blobstore image

  24. 24

    get Thumbnail image from wikimedia commons

  25. 25

    How to get image thumbnail from given link?

  26. 26

    Get an image from the video

  27. 27

    Youtube get image url from channel (not getting image)

  28. 28

    Getting a thumbnail of a *.mov video IOS

  29. 29

    Taking thumbnail image from video always returns null

HotTag

Archive