UIImagePickerController视频最大尺寸

问题描述 投票:0回答:2

我正在使用UIImagePickerController录制视频,并且我需要视频的最长持续时间为30秒或最大大小为40 MB。默认情况下,我已将其设置为videoMaximumDuration,但我不知道如何限制视频的最大大小,是否有任何限制视频大小的想法?

swift xcode uiimagepickercontroller
2个回答
0
投票

您不能限制显示的内容,也不能阻止用户选择较小的视频。用户选择后,您可以查看文件并决定不对其进行任何操作,或要求用户选择相应的警报。


0
投票

请参考此库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
                        }
© www.soinside.com 2019 - 2024. All rights reserved.