2016-10-26 11 views
1

これは私の最初の質問ですので、よく説明されていない場合はお知らせください。AVCaptureDevicePosition.frontが機能していません

だから、基本的に私は、このコードで、フロントカメラにアクセスしようとしている:私はすべてが魔法のように動作し、バックカメラ位置を変更すると

captureSession = AVCaptureSession() 
    captureSession?.sessionPreset = AVCaptureSessionPreset1920x1080 

    let cameraDevice = AVCaptureDevice.defaultDevice(withDeviceType: AVCaptureDeviceType.builtInWideAngleCamera , mediaType: AVMediaTypeVideo, position: AVCaptureDevicePosition.front) 
    print(cameraDevice!) 


    let error: NSError? = nil 

    do{ 
    let input = try AVCaptureDeviceInput(device: cameraDevice) 

     print(captureSession.canAddInput(input)) 

     if error == nil && captureSession.canAddInput(input){ 
      captureSession?.addInput(input) 

      stillImageOutput = AVCaptureStillImageOutput() 
      if captureSession.canAddOutput(stillImageOutput){ 
       captureSession.addOutput(stillImageOutput) 
       previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) 
       previewLayer?.videoGravity = AVLayerVideoGravityResizeAspect 
       previewLayer?.connection.videoOrientation = AVCaptureVideoOrientation.portrait 
       cameraView.layer.addSublayer(previewLayer!) 
       stillImageOutput?.outputSettings = [AVVideoCodecKey:AVVideoCodecJPEG] 

       captureSession?.startRunning() 



      } 

     } 

そのコードにprint(captureSession.canAddInput(input))戻りfalseを使用してますが。何か不足していますか?

答えて

0

どのデバイスを使用しているのかわかりませんが、iPhone 6/6plusでは、そのプリセット解像度がフロントカメラにとって高すぎます。アップルのドキュメントを1として

https://developer.apple.com/library/content/documentation/DeviceInformation/Reference/iOSDeviceCompatibility/Cameras/Cameras.html

、それらのデバイス上で最高の静止画撮影解像度が低く、プリセットを使用してみてください、それはフロントカメラに動作するかどうかを確認1280×960です。

なぜなら、バックカメラでこれがうまく動作する理由は、これが高い解像度をサポートしているからです。

+0

ありがとうございました!これは完璧に動作します! – viggurt

関連する問題