3

我们正在开发一个 ios 相机应用程序,它具有以下功能:图片/视频捕获、媒体文件管理、媒体共享等。我们的登陆屏幕是相机预览屏幕。这有许多按钮可以导航到其他屏幕。

如果我们在取景器屏幕上,然后锁定和解锁手机,预览仍然可以。但是如果我从取景器导航到另一个屏幕并返回到取景器然后进行锁定和解锁,相机预览就会卡住,即屏幕将显示最后一帧。但按钮等是可导航的。这是我们得到的错误:

Capture session runtime error: Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSUnderlyingError=0x1490838e0 {Error Domain=NSOSStatusErrorDomain Code=-12780 "(null)"}, NSLocalizedFailureReason=An unknown error occurred (-12780), NSLocalizedDescription=The operation could not be completed

什么是查看预览最稳定和有效的方式?

一些相关的代码片段:

   -(void) setGUIBasedOnMode{
    if (![self isStreamStarted]) {
        if (shutterActionMode == SapCamSelectionModeLiveStream)
        {
            _flashButton.hidden = true;
            _cameraButton.hidden = true;
            _liveSteamSession = [[VCSimpleSession alloc] initWithVideoSize:[[UIScreen mainScreen]bounds].size frameRate:30 bitrate:1000000 useInterfaceOrientation:YES];
            [_liveSteamSession.previewView removeFromSuperview];
            AVCaptureVideoPreviewLayer  *ptr;
            [_liveSteamSession getCameraPreviewLayer:(&ptr)];
            _liveSteamSession.previewView.frame = self.view.bounds;
            _liveSteamSession.delegate = self;
        }
        else{
            [_liveSteamSession.previewView removeFromSuperview];
            _liveSteamSession.delegate = nil;
//            [self removeObservers];
            _cameraButton.hidden = false;
            if(flashFlag == 0){
                _flashButton.hidden = false;
            }
            else if(flashFlag == 1){
                _flashButton.hidden = true;
            }
            self.session = [[AVCaptureSession alloc] init];
            self.previewView.hidden = false;
            self.previewView.session = self.session;
            [self configureCameraSettings];

            dispatch_async( self.sessionQueue, ^{
                switch ( self.setupResult )
                {
                    case AVCamSetupResultSuccess:
                    {
                        [self addObservers];
                        [self.session startRunning];

                        self.sessionRunning = self.session.isRunning;
                        if(loadingCameraFlag == false){
                            [self hidingView];
                        }
                        break;
                    }
                    case AVCamSetupResultCameraNotAuthorized:
                    {
                        dispatch_async( dispatch_get_main_queue(), ^{
                            NSString *message = NSLocalizedString( @"App doesn't have permission to use the camera, please change privacy settings", @"Alert message when the user has denied access to the camera");
                            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"AVCam" message:message preferredStyle:UIAlertControllerStyleAlert];
                            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"Alert OK button" ) style:UIAlertActionStyleCancel handler:nil];
                            [alertController addAction:cancelAction];

                            UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"Settings", @"Alert button to open Settings" ) style:UIAlertActionStyleDefault handler:^( UIAlertAction *action ) {
                                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                            }];
                            [alertController addAction:settingsAction];
                            [self presentViewController:alertController animated:YES completion:nil];
                        } );
                        break;
                    }
                    case AVCamSetupResultSessionConfigurationFailed:
                    {
                        dispatch_async( dispatch_get_main_queue(), ^{
                            NSString *message = NSLocalizedString( @"Unable to capture media", @"Alert message when something goes wrong during capture session configuration" );
                            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString( @"OK", @"Alert OK button" ) style:UIAlertActionStyleCancel handler:nil];
                            [alertController addAction:cancelAction];
                            [self presentViewController:alertController animated:YES completion:nil];
                        } );
                        break;
                    }
                }
            });
        }
    }
}

更多的:

[self.session beginConfiguration];

if ( [self.session canAddInput:videoDeviceInput] ) {
    [self.session addInput:videoDeviceInput];
    self.videoDeviceInput = videoDeviceInput;

    dispatch_async( dispatch_get_main_queue(), ^{
        UIInterfaceOrientation statusBarOrientation = [UIApplication sharedApplication].statusBarOrientation;
        AVCaptureVideoOrientation initialVideoOrientation = AVCaptureVideoOrientationPortrait;
        if ( statusBarOrientation != UIInterfaceOrientationUnknown ) {
            initialVideoOrientation = (AVCaptureVideoOrientation)statusBarOrientation;
        }
        AVCaptureVideoPreviewLayer *previewLayer = (AVCaptureVideoPreviewLayer *)self.previewView.layer;
        previewLayer.connection.videoOrientation = initialVideoOrientation;
    } );
}
else {
    self.setupResult = AVCamSetupResultSessionConfigurationFailed;
}
4

0 回答 0