首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法设置视频录制的最长持续时间?

无法设置视频录制的最长持续时间?
EN

Stack Overflow用户
提问于 2018-09-23 18:45:45
回答 2查看 1.1K关注 0票数 0

我已经创建了一个自定义相机,我想将最大录制时间设置为30秒。这里是为设置最大值而编写代码的地方。

代码语言:javascript
复制
@objc func videoAction(sender: UIButton){

    if(imageSetAction()){
        videoImage.image = UIImage(named: "video")
        flashButton.isHidden = true
        videoLabel.textColor = ConstantColors.selectedTextColor
        currentSelected = sender.tag
        if(videoButton.isEnabled){
            if(photoOutput != nil){
                captureSession.removeOutput(photoOutput!)
            }

            self.movieFileOutput = AVCaptureMovieFileOutput()
            self.movieFileOutput?.maxRecordedDuration = CMTime(seconds: 30, preferredTimescale: 600)
            if captureSession.canAddOutput(movieFileOutput!) {
                captureSession.addOutput(movieFileOutput!)
            }
            captureSession.commitConfiguration()
            captureSession.sessionPreset = AVCaptureSession.Preset.high
        }
        let longPressGesture = UILongPressGestureRecognizer.init(target: self, action: #selector(handleLongPress))
        self.semiCircleView.addGestureRecognizer(longPressGesture);
        videoButton.isEnabled = false
    }
}

在相同的情况下,我有一个用户编辑视频的选项,所以我在委托方法中调用默认视频编辑器。

代码语言:javascript
复制
func fileOutput(_ output: AVCaptureFileOutput, didFinishRecordingTo outputFileURL: URL, from connections: [AVCaptureConnection], error: Error?) {
    if error == nil {
        //UISaveVideoAtPathToSavedPhotosAlbum(outputFileURL.path, nil, nil, nil)
        if UIVideoEditorController.canEditVideo(atPath: outputFileURL.path){
            let videoEditorController = UIVideoEditorController()
            videoEditorController.delegate = self
            videoEditorController.videoPath = outputFileURL.path
            videoEditorController.modalPresentationStyle = .popover
            videoEditorController.popoverPresentationController?.sourceView = self.view
            present(videoEditorController, animated: true, completion: nil)
        }
    }
    print("completed")
}

func fileOutput(_ output: AVCaptureFileOutput, didStartRecordingTo fileURL: URL, from connections: [AVCaptureConnection]) {
    movieFileOutput?.maxRecordedDuration = CMTimeMake(30, 1)

    /* After 30 seconds, let's stop the recording process */
    DispatchQueue.main.asyncAfter(deadline: .now() + 30.0, execute: {
        debugPrint("longpress ended")
        self.movieFileOutput?.stopRecording()
        self.removeProgressBar()
    })
}

不知道为什么,但录像只录了10秒。任何帮助都是非常感谢的。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-09-23 19:12:11

来自苹果公司关于maxRecordedDuration方法的文档。

此属性指定记录文件持续时间的硬限制。达到限制时停止记录,并以适当的错误调用fileOutput(_:didFinishRecordingTo:from:error:)委托方法。此属性的默认值无效,表示无限制。

也许您不应该停止录制自己,如果它将停止在fileOutput(_:didFinishRecordingTo:from:error:)方法。

票数 2
EN

Stack Overflow用户

发布于 2020-04-15 14:45:04

到达maximumDuration时将调用委托方法,但错误不会为零。

函数fileOutput(_ output: AVCaptureFileOutput,didFinishRecordingTo outputFileURL: URL,from connections: AVCaptureConnection,error: Error?)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52469187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档