// 本地图库按钮监听
-(void)pictureClicked{
UIImagePickerController *pickerController = [[UIImagePickerController alloc]init];
pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.mediaTypes =@[(NSString*)kUTTypeMovie];
pickerController.allowsEditing=YES;
pickerController.delegate=self;
[self.navigationController presentViewController:pickerController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionaryid> *)info{
[pickerdismissViewControllerAnimated:YES completion:nil];
//这个是获取本地图库视频的路径
NSURL *URL = info[UIImagePickerControllerMediaURL];
NSString*URLStr = [NSStringstringWithFormat:@"%@",URL];
//获取本地视频的第一帧当作封面
AVURLAsset*asset = [[AVURLAssetalloc]initWithURL:URLoptions:nil];
AVAssetImageGenerator *assetGen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
assetGen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError*error =nil;
CMTimeactualTime;
CGImageRefimage = [assetGencopyCGImageAtTime:timeactualTime:&actualTimeerror:&error];
//这个就是第一帧的图片了
UIImage*videoImage = [[UIImagealloc]initWithCGImage:image];
// 获取本地视频的时长
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset*urlAsset = [AVURLAssetURLAssetWithURL:URLoptions:opts];
floatsecond = urlAsset.duration.value/ urlAsset.duration.timescale;
if(second >60){
SHOW_ALERT(@"视频长度不能大于一分钟");
}else{
SHOW_ALERT(@"这里写业务逻辑");
}
}