5

我有一个问题AVCaptureSession startRunning。仅在带有 IOS 7 的 iphone 5 上才有问题。我的应用程序应该录制视频并显示所有内容AVCaptureVideoPreviewLayer,但如果我在 iphone 5 上测试,第一次通话错误 = AVErrorMediaServicesWereReset. 这是我的代码,我在其中创建 capturemanager 和startRunning

    -(void)startVideoTranslation{   
    CGRect r = videoBackView.bounds;

    videoPreviewView = [[UIView alloc] initWithFrame:r];
    [videoBackView addSubview:videoPreviewView];

    if (currentGameType == MPGameTypeCrocodile){
        if (captureManager == nil) {
            captureManager = [[AVCamCaptureManager alloc] init];

            [captureManager setDelegate:self];
            if ([captureManager setupSession]) {
                //Create video preview layer and add it to the UI

                AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[captureManager session]];
                CALayer *viewLayer = [videoPreviewView layer];
                [viewLayer setMasksToBounds:YES];

                CGRect bounds = [videoPreviewView bounds];
                bounds.origin.y = bounds.origin.y+1;
                [newCaptureVideoPreviewLayer setFrame:bounds];

                if ([newCaptureVideoPreviewLayer.connection isVideoOrientationSupported]) {
                    [newCaptureVideoPreviewLayer.connection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight];
                }

                [newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];

                [viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];

                captureVideoPreviewLayer = newCaptureVideoPreviewLayer;


                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isErrorSession:) name:AVCaptureSessionRuntimeErrorNotification object:nil];
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
                        [[captureManager session] startRunning];
                    });
            }
        }
    }

}

我在这里调用的这个选择器:

-(void)showPrepareView{
[self playSound:@"start"];

BGView.frame = videoBackView.bounds;

[prepareView addSubview:videoBackView];
[self startVideoTranslation];
[videoBackView addSubview:BGView];

在我使用的这段代码AVAudioPlayer[self playSound:]videobackView我添加了我的PreviewLayer.

有谁知道这个问题的原因?

现在,我解决了这个问题,我进入 -(id)initWithFrame:

captureManager = [[AVCamCaptureManager alloc] init];
[captureManager setDelegate:self]
[captureManager setupSession];
[[captureManager session] startRunning];

但我不明白它是什么。

4

0 回答 0