【问题标题】:UIImagePickerController video maximun sizeUIImagePickerController 视频最大尺寸
【发布时间】:2020-01-03 05:47:03
【问题描述】:

我正在使用 UIImagePickerController 录制视频,我需要一个最长持续时间为 30 秒 或最大大小为 40 MB 的视频.默认情况下我已设置它 videoMaximumDuration,但我不知道如何限制视频的最大尺寸,有没有办法限制视频尺寸?

【问题讨论】:

  • 我认为您不能限制视频大小,因为用户可以选择任何大小的视频。您可以在发送到服务器之前对其进行压缩。

标签: swift xcode uiimagepickercontroller


【解决方案1】:

请参考这个库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
                        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-30
    • 2011-05-06
    • 2011-11-08
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多