2016-04-09 29 views
0

Programlamada yeniyim ve snapchat gibi bir video yakalama oluşturmaya çalışıyorum. Video kaydetme ve kaydetme konusunda sorun yaşıyorum. C'yi bilmiyorum ama belgelere baktım ve en iyisi Swift 2.0'a dönüştü.Bir video yakalama uygulaması oluşturmaya çalışırken Xcode'ta bir çökme yaşanıyor

15 saniyelik bir süreye kadar kayıt yapabilmenizi sağlayacak bir video kaydediciyi hızlı bir şekilde oluşturmak için lütfen herhangi bir kişi yardım edebilir ve/veya bazı kaynaklar hakkında tavsiyelerde bulunabilir.

hatası:

[AVCaptureMovieFileOutput startRecordingToOutputFileURL: recordingDelegate:]

+0

Bir kilitlenmenin nasıl giderileceğini öğrenmek için aşağıdakilere bakın: http://www.raywenderlich.com/10209/my-app-crashed-now-what-part-1 – rmaddy

+0

Sorunuzu eksiksiz hata mesajıyla güncellemeniz ve soruna neden olan tam çizgiyi işaret etmeniz gerekmektedir. – rmaddy

cevap

0

Hatam, ben çıkışları eklemek daha sonra ilk yapılandırmayı işlemek ve zorunda olduğunu fark

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)") 
    } 
} 

}

İlgili konular