我从照片库中的视频获得了缩略图,现在我想在图像缩略图上添加持续时间和相机图标。有什么建议吗?感谢。
答案 0 :(得分:4)
当你从图书馆选择视频文件时,你可以获得视频的持续时间: -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
selectedVideoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
AVPlayerItem *SelectedItem = [AVPlayerItem playerItemWithURL:selectedVideoUrl];
CMTime duration = SelectedItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);
}
你可以使用以下方式获取视频: -
-(UIImage *)getThumbNail:(NSString*)stringPath
{
//stringPath is a path of stored video file from document directory
NSURL *videoURL = [NSURL fileURLWithPath:stringPath];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
return thumbnail;
}
现在您只需要创建自定义视图并执行所需操作。
不要忘记添加
#import <MediaPlayer/MediaPlayer.h>
#import <AVFoundation/AVFoundation.h>
#import <AVFoundation/AVAsset.h>
这里还有一个很合适的答案 与您的问题请检查Bellow: -
iOS: get video duration and thumbnails without playing video