最近拡張型のVRアプリケーションを作成しています。これはXcodeのswift 3でGVRSDKを使用しています。私は一からそれを作成しなければなりませんでした。とにかく私はちょうど終わったと私は私が私の出力からこれを得、それを実行しました:私は再びそれを実行しましたが、GVRキットへのすべての参照を処分したし、それが完璧に走ったは致命的なエラーを修正できません:オプションの値をアンラッピングしている間に予期せずnilが見つかりません
fatal error: unexpectedly found nil while unwrapping an Optional value
。
ご覧のとおり、コードを実行するとエラーが表示されません。
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet var previewView: GVRPanoramaView!
@IBOutlet weak var captureButton: UIButton!
@IBOutlet weak var messageLabel: UILabel!
var captureSession: AVCaptureSession?
var videoPreviewLayer: AVCaptureVideoPreviewLayer?
var capturePhotoOutput: AVCapturePhotoOutput?
override func viewDidLoad() {
super.viewDidLoad()
captureButton.layer.cornerRadius = captureButton.frame.size.width/2
captureButton.clipsToBounds = true
// Get an instance of the AVCaptureDevice class to initialize a device object and provide the video as the media type parameter
let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
do {
// Get an instance of the AVCaptureDeviceInput class using the previous deivce object
let input = try AVCaptureDeviceInput(device: captureDevice)
// Initialize the captureSession object
captureSession = AVCaptureSession()
// Set the input devcie on the capture session
captureSession?.addInput(input)
// Get an instance of ACCapturePhotoOutput class
capturePhotoOutput = AVCapturePhotoOutput()
capturePhotoOutput?.isHighResolutionCaptureEnabled = true
// Set the output on the capture session
captureSession?.addOutput(capturePhotoOutput)
// Initialize a AVCaptureMetadataOutput object and set it as the input device
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession?.addOutput(captureMetadataOutput)
//Initialise the video preview layer and add it as a sublayer to the viewPreview view's layer
videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
videoPreviewLayer?.frame = view.layer.bounds
previewView.layer.addSublayer(videoPreviewLayer!)
//Initialise gogle cardboard preview mode
previewView.enableCardboardButton = true
//start video capture
captureSession?.startRunning()
} catch {
//If any error occurs, simply print it out
print(error)
return
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
私は私が持っているGVRPanoramaViewに何かが、確かではないと思う: は、ここでは、コードです。ありがとうございました!
こんにちは、お返事ありがとうございます。あなたはこの問題を回避する方法を知っていますか?多分私はそれに価値を割り当てることができますか? –
私はその問題を回避しました!ありがとうございました。私は別のエラーに遭遇しました、私のpreviewView.enableCardboardButton =真は上に表示されません、そして、私は画面の周りをタップするだけで、私はGoogleのV.Rのヘルプページに行く。私は何ができるのか知っていますか? –
VRやそのシステムがどのように機能するかわからないので、あなたがここにあるこの質問に答える方法。 – impression7vx