第一种方法:并可以获取到视频的缩略图,原文地址:http://blog.csdn.net/xiaobo16/article/details/7759181
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
NSString *mediaType = [infoobjectForKey:UIImagePickerControllerMediaType];
if([mediaType isEqualToString:@"public.movie"])
{
NSURL *videoURL = [infoobjectForKey:UIImagePickerControllerMediaURL];
NSLog(@"found a video");
//获取视频的thumbnail
MPMoviePlayerController *player = [[[MPMoviePlayerControlleralloc]initWithContentURL:videoURL] autorelease];
UIImage *thumbnail = [playerthumbnailImageAtTime:1.0timeOption:MPMovieTimeOptionNearestKeyFrame];
player = nil;
}
}
第二种方法,通过判断是否含有视频轨道,参考地址:http://www.thinksaas.cn/ask/question/22483/
- (void)imagePickerController: (UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info{
NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
AVAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:info];
NSArray *tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
//判断是否含有视频轨道
BOOL hasVideoTrack = [tracks count] > 0;
if (hasVideoTrack) {
[picker dismissViewControllerAnimated:YES completion:^{
}];
return;
}
}