私のミス、私は出力を追加し、その後第1の構成をコミットしなければならないことを理解
import UIKit
import AVFoundation
import CoreGraphics
class CameraControllerViewController: UIViewController, AVCaptureFileOutputRecordingDelegate {
@IBOutlet weak var videoPreviewView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
//Create Capture Session
let captureSession = AVCaptureSession()
captureSession.beginConfiguration()
if captureSession.canSetSessionPreset(AVCaptureSessionPresetHigh){
captureSession.sessionPreset = AVCaptureSessionPresetHigh
}
//Add input device
let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
//Create Input
do{
let captureInput = try AVCaptureDeviceInput(device: captureDevice)
captureSession.addInput(captureInput)
}catch let error as NSError{
NSLog(error.debugDescription)
}
//PreviewLayer
let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = videoPreviewView.bounds
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
videoPreviewView.layer.addSublayer(previewLayer)
//OutPut
let format = NSDateFormatter()
format.dateFormat = "yyyy-MM-dd-HH-mm-ss"
let currentFileName = "\(format.stringFromDate(NSDate())).mp4"
let documentsDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0]
let videoFileURL = documentsDirectory.URLByAppendingPathComponent(currentFileName)
let movieFileOutput = AVCaptureMovieFileOutput()
movieFileOutput.startRecordingToOutputFileURL(videoFileURL, recordingDelegate: self)
if captureSession.canAddOutput(movieFileOutput){
captureSession.addOutput(movieFileOutput)
}
captureSession.commitConfiguration()
captureSession.startRunning()
captureSession.stopRunning()
}
func captureOutput(captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAtURL fileURL: NSURL!, fromConnections connections: [AnyObject]!) {
NSLog("Recording did start to file: \(NSURL.debugDescription())")
}
func captureOutput(captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAtURL outputFileURL: NSURL!, fromConnections connections: [AnyObject]!, error: NSError!) {
if let error = error{
NSLog("Error: \(error.debugDescription)")
}else{
NSLog("File Output: \(outputFileURL.debugDescription)")
}
}
}
クラッシュをデバッグする方法については、以下を参照してください。http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – rmaddy
質問を完全なエラーメッセージで更新し、問題の原因となっている正確な行を指摘する必要があります。 – rmaddy