简体   繁体   中英

How to solve error protocol recording video in swift?

I'm trying record video with AVFoundation. In objective c I had a protocol definition to delegate in .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:

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):

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM