我正在使用UIImagePickerController录制视频,并且我需要视频的最长持续时间为30秒或最大大小为40 MB。默认情况下,我已将其设置为videoMaximumDuration,但我不知道如何限制视频的最大大小,是否有任何限制视频大小的想法?
您不能限制显示的内容,也不能阻止用户选择较小的视频。用户选择后,您可以查看文件并决定不对其进行任何操作,或要求用户选择相应的警报。
请参考此库https://github.com/zhangao0086/DKImagePickerController
let maxDuration:Float64 = 60
let videoDuration = asset!.duration
let videoDurationSeconds = CMTimeGetSeconds(videoDuration)
if videoDurationSeconds > maxDuration {
if UIVideoEditorController.canEditVideoAtPath(asset!.URL.path!) {
let videoEditor = UIVideoEditorController()
self.videoEditor.videoPath = asset!.URL.path!
self.videoEditor.videoMaximumDuration = 60.0
self.presentViewController(self.videoEditor, animated: true, completion: nil)
}
}
// MARK: - UIVideoEditorControllerDelegate
func videoEditorController(editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) {
self.videoEditor.dismissViewControllerAnimated(true, completion: nil)
//Do whatever you wish with the trimmed video here
}