我想在我的uiimageview for iphone中显示来自网址的视频的视频图像

时间:2013-07-31 05:45:17

标签: iphone ios video-streaming video-thumbnails

是否可以获取视频的第一个图像帧并在uiimageview中显示它。我的视频保存在服务器中。我需要调用网址来播放视频

3 个答案:

答案 0 :(得分:3)

一个例子:

NSURL *videoURl = [NSURL fileURLWithPath:videoPath];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURl options:nil];
AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset];
generate.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 60);
CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err];

UIImage *img = [[UIImage alloc] initWithCGImage:imgRef];
[YourImageView setImage:img];

希望有所帮助......

答案 1 :(得分:3)

我使用这种方法做同样的事情

/**
 *  This method retunrs a thumbnail of a Video file
 */

+ (UIImage *)generateThumbnailIconForVideoFileWith:(NSURL *)contentURL WithSize:(CGSize)size
{
    UIImage *theImage = nil;
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:contentURL options:nil];
    AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    generator.maximumSize=size;
    generator.appliesPreferredTrackTransform = YES;
    NSError *err = NULL;
    CMTime time = CMTimeMake(100,100); //change whatever you want here.
    CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:&err];
    theImage = [[UIImage alloc] initWithCGImage:imgRef] ;
    CGImageRelease(imgRef);
    return theImage;
}

答案 2 :(得分:0)

您可以使用MPMoviePlayerController之类的方式执行此操作..

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:yourVideoURL];
UIImage *videoThumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];

另请参阅此链接getting-thumbnail-from-a-video-url-or-data-in-iphone-sdk

中与AVURLAsset的其他答案