我想从视频获取缩略图(的第一帧),所以我可以显示它。任何人都可以做到这一点成功?如果是这样,你做到了吗?Iphone sdk显示缩略图
0
A
回答
0
首先你应该有videoURL或nsdata的视频。现在添加MediaPlayer框架和#import MediaPlayer/MPMoviePlayerController.h。添加这个您要thumbail视频
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
[player release];
1
有多种方法第一种是使用AssetImageGenerator号: -
- (UIImage *)imageFromVideoURL
{
// result
UIImage *image = nil;
// AVAssetImageGenerator
AVAsset *asset = [[AVURLAsset alloc] initWithURL:appDelegate.videoURL options:nil];;
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
imageGenerator.appliesPreferredTrackTransform = YES;
// calc midpoint time of video
Float64 durationSeconds = CMTimeGetSeconds([asset duration]);
CMTime midpoint = CMTimeMakeWithSeconds(durationSeconds/2.0, 600);
// get the image from
NSError *error = nil;
CMTime actualTime;
CGImageRef halfWayImage = [imageGenerator copyCGImageAtTime:midpoint actualTime:&actualTime error:&error];
if (halfWayImage != NULL)
{
// cgimage to uiimage
image = [[UIImage alloc] initWithCGImage:halfWayImage];
[dic setValue:image forKey:kImage];
NSLog(@"Values of dictonary==>%@", dic);
NSLog(@"Videos Are:%@",appDelegate.videoURLArray);
CGImageRelease(halfWayImage);
}
return image;
}
这是另一种方法是使用的MPMoviePlayerController的最佳方法: -
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
[player stop];
这可能会帮助你,谢谢:)
相关问题
- 1. 显示缩略图
- 2. iphone sdk> 3.0。视频缩略图?
- 3. 缩略图显示问题
- 4. PDF缩略图未显示
- 5. 显示特定缩略图
- 6. PDF缩略图显示
- 7. Facebook不显示缩略图
- 8. iPad detailedViewController显示缩略图
- 9. 在iPhone上显示多个图像缩略图时UI失真
- 10. iOS SDK发布链接并显示缩略图
- 11. Bootstrap缩略图列表未显示缩略图
- 12. 缩略图脚本将不会显示缩略图
- 13. 如何缩略图幻灯片只显示缩略图pic
- 14. 显示所选图像的缩略图
- 15. RefineryCMS图像缩略图没有显示
- 16. 将图像显示为缩略图
- 17. Magento 1.7缩略图图像不显示
- 18. 显示一组图像的缩略图
- 19. 使用QItemDelegate显示图像缩略图
- 20. Jquery Galleria缩略图不显示
- 21. Facebook的缩略图未显示
- 22. 使用php显示缩略图pdf
- 23. WordPress显示缩略图不起作用
- 24. 在JPanel上显示JFreeChart的缩略图
- 25. Royal Slider只显示一个缩略图
- 26. 如何显示YouTube视频缩略图
- 27. 视频以缩略图显示?
- 28. 像按钮不显示缩略图
- 29. 显示缩略图和文本对齐
- 30. 显示视频的缩略图
感谢您的回复.... – user1376474
欢迎是有帮助的吗? –