(腾讯视频)iOS开发之视频根据url获取第一帧图片,获取任一帧图片

#import <AVFoundation/AVFoundation.h>

+ (UIImage*) thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time {  AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];

NSParameterAssert(asset);

  AVAssetImageGenerator *assetImageGenerator =[[AVAssetImageGenerator alloc] initWithAsset:asset];

assetImageGenerator.appliesPreferredTrackTransform = YES;

   assetImageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;

CGImageRef thumbnailImageRef = NULL;

  CFTimeInterval thumbnailImageTime = time;

  NSError *thumbnailImageGenerationError = nil;

     thumbnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60)actualTime:NULL error:&thumbnailImageGenerationError];

  if(!thumbnailImageRef)

      NSLog(@"thumbnailImageGenerationError %@",thumbnailImageGenerationError);

      UIImage*thumbnailImage = thumbnailImageRef ? [[UIImage alloc]initWithCGImage: thumbnailImageRef] : nil;

    return thumbnailImage;

}

-(void)setADvideoUrl:(NSString *)urlstr

{

    urlstr = urlstr;

    NSLog(@"%@",urlstr);

    //http://v.qq.com/iframe/player.html?vid=k0511h0fvay&tiny=1&auto=0  大图

    NSURL * url = [NSURLURLWithString:urlstr];

    NSString * hostStr = [url host];

    NSString * tXURL = @"v.qq.com";

    //https://puui.qpic.cn/qqvideo_ori/0/k0511h0fvay_228_128/0  小图

    NSString * videoPrewURL = nil;

    if([tXURL isEqualToString:hostStr]){ //如果是腾讯视频

        NSDictionary * dic = [urlstr getURLParameters];

        NSString * videoIDStr = [dic objectForKey:@"vid"];

        if(videoIDStr){

            videoPrewURL = [NSStringstringWithFormat:@"https://puui.qpic.cn/qqvideo_ori/0/%@_228_128/0",videoIDStr];

            NSLog(@"videoIDStr is %@",videoPrewURL);

        }

}

}

上一篇:适配ios9出现的问题:-canOpenURL: failed for URL


下一篇:第18章 图元文件_18.1 老式图元文件格式(wmf)