Пример #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Disable UI. The UI is enabled if and only if the session starts running.
            MetadataObjectTypesButton.Enabled = false;
            SessionPresetsButton.Enabled      = false;
            CameraButton.Enabled = false;
            ZoomSlider.Enabled   = false;

            // Add the open barcode gesture recognizer to the region of interest view.
            PreviewView.AddGestureRecognizer(OpenBarcodeURLGestureRecognizer);

            // Set up the video preview view.
            PreviewView.Session = session;

            // Check video authorization status. Video access is required and audio
            // access is optional. If audio access is denied, audio is not recorded
            // during movie recording.
            switch (AVCaptureDevice.GetAuthorizationStatus(AVMediaType.Video))
            {
            case AVAuthorizationStatus.Authorized:
                // The user has previously granted access to the camera.
                break;

            case AVAuthorizationStatus.NotDetermined:
                // The user has not yet been presented with the option to grant
                // video access. We suspend the session queue to delay session
                // setup until the access request has completed.
                sessionQueue.Suspend();
                AVCaptureDevice.RequestAccessForMediaType(AVMediaType.Video, granted => {
                    if (!granted)
                    {
                        setupResult = SessionSetupResult.NotAuthorized;
                    }
                    sessionQueue.Resume();
                });
                break;

            default:
                // The user has previously denied access.
                setupResult = SessionSetupResult.NotAuthorized;
                break;
            }

            // Setup the capture session.
            // In general it is not safe to mutate an AVCaptureSession or any of its
            // inputs, outputs, or connections from multiple threads at the same time.
            // Why not do all of this on the main queue?
            // Because AVCaptureSession.StartRunning() is a blocking call which can
            // take a long time. We dispatch session setup to the sessionQueue so
            // that the main queue isn't blocked, which keeps the UI responsive.
            sessionQueue.DispatchAsync(ConfigureSession);
        }