简体   繁体   English

如何解决错误协议快速录制视频?

[英]How to solve error protocol recording video in swift?

I'm trying record video with AVFoundation. 我正在尝试使用AVFoundation录制视频。 In objective c I had a protocol definition to delegate in .h: 在目标c中,我有一个协议定义要委托给.h:

 @protocol AVCaptureManagerDelegate <NSObject>
 - (void)didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
                                  error:(NSError *)error;
 @end


 @interface AVCaptureManager : NSObject

 @property (nonatomic, assign) id<AVCaptureManagerDelegate> delegate;

And in swift need this code to save in out url with recordingDelegate, but need delegate: 并迅速需要以下代码使用recordingDelegate保存到URL中,但需要委托:

self.movieFileOut.startRecordingToOutputFileURL(filePath, recordingDelegate)

I'm confused.. Thanks!! 我很困惑..谢谢!

Here's some code in swift fore recording a video. 这是一些快速录制视频的代码。 The first thing is to define a delegate : 首先是定义一个委托:

import Foundation
import AVFoundation
import UIKit

class VideoDelegate : NSObject, AVCaptureFileOutputRecordingDelegate
{

    func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
    println("capture output : finish recording to \(outputFileURL)")
    }

    func captureOutput(captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtURL fileURL: NSURL!, fromConnections connections: [AnyObject]!) {
        println("capture output: started recording to \(fileURL)")
    }

}

After that , calling the startRecordingToOutputFileURL (Assuming session is a AVCaptureSession): 之后,调用startRecordingToOutputFileURL(假设会话是AVCaptureSession):

let videoDelegate = VideoDelegate()
let fileOutput = AVCaptureMovieFileOutput()
session.addOutput(fileOutput)
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString
let outputPath = "\(documentsPath)/output.mov"
let outputFileUrl = NSURL(fileURLWithPath: outputPath)
fileOutput.startRecordingToOutputFileURL(outputFileUrl, recordingDelegate: videoDelegate)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在swift中解决错误“viewController与协议UIScrollViewDelegate的冗余一致性? - How to solve the error "Redundant conformance of viewController to protocol UIScrollViewDelegate in swift? 如何解决 Protocol 'Result' as a type cannot conform to the protocol itself error in swift 5.6 - How to solve Protocol 'Result' as a type cannot conform to the protocol itself error in swift 5.6 如何快速将录像保存到文档目录? - How to save video recording to documents directory with swift? 如何解决Xcode 7中没有类型或协议命名错误? - How To Solve No Type or Protocol Named Error In Xcode 7? 在 Swift 3 中使用 AVCaptureVideoDataOutput 录制视频 - Recording Video Using AVCaptureVideoDataOutput at Swift 3 在iOS Swift中录制视频时如何捕获照片? - How to capture photo while recording video in iOS Swift? Swift 3:如何在使用 AVFoundation 的视频录制过程中将麦克风静音/取消静音 - Swift 3: How to mute / unmute microphone during video recording using AVFoundation OpenCV IOS Swift 2:如何实现CvVideoCameraDelegate协议处理视频帧 - OpenCV IOS Swift 2 :How to implement the CvVideoCameraDelegate protocol process Video Frames 如何使用AVCaptureVideoDataOutput处理错误并获取当前录制的视频大小? - How to handle error and get current recording video size using AVCaptureVideoDataOutput ? 录制时在视频中添加音频-Swift 4 - Add audio to my video when recording - Swift 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM