美文网首页
iOS系统自带UIImagePickerController选择

iOS系统自带UIImagePickerController选择

作者: novice_Qin | 来源:发表于2019-11-25 17:16 被阅读0次

1.选择视频的时候就判断视频长度,这种情况一般都需要能剪切视频

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

 imagePicker.allowsEditing = YES;//这步一定要设置为YES,不然无法控制时长

 imagePicker.videoMaximumDuration = 15;//(以s为单位)

 imagePicker.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];

imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

2.选择完视频后判断视频时长等,在didFinish里进行下面的判断即可

 NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]

                 forKey:AVURLAssetPreferPreciseDurationAndTimingKey];

 AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:url options:opts];

 // 初始化视频媒体文件

 float minute = 0, second = 0;

 second = urlAsset.duration.value / urlAsset.duration.timescale;

 if(second > 15){

  .......

 }

相关文章

网友评论

      本文标题:iOS系统自带UIImagePickerController选择

      本文链接:https://www.haomeiwen.com/subject/xpifwctx.html