相关疑难解决方法(0)

视频在AVFoundation的相机开关上冻结

我制作了一款具有拍摄和保存视频功能的应用.我已经使用了AVFoundation,Apple的AVCam一直是我的向导.

我希望我能说清楚:
一切正常,直到我发布第一次处理AVCamCaptureManager的videoViewController(在AVCam中将是AVCamViewController).之后,当我再次创建它时,视频会在相机切换后立即冻结.即使重新运行也无济于事,也无法清理或重置设备.(有时候其中一件事有所帮助,但这不是一条规则).

我不需要保存内存时释放videoViewController.

切换摄像头的代码与AVCam基本相同:

NSError *error;
AVCaptureDeviceInput *newVideoInput;
AVCaptureDevicePosition position = currentVideoInput.device.position;

if (position == AVCaptureDevicePositionBack)
    newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:frontFacingCamera error:&error];
else if (position == AVCaptureDevicePositionFront)
    newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error];

if (newVideoInput != nil) {
    [session beginConfiguration];
    [session removeInput:currentVideoInput];
    if ([session canAddInput:newVideoInput]) {
        [session addInput:newVideoInput];
        [self setVideoInput:newVideoInput];
} else {
    [session addInput:currentVideoInput];
}
    [session commitConfiguration];
    [newVideoInput release];
} else if (error) {
    NSLog(@"%@",[error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)

用于解除videoView的代码

[self.videoViewController.view removeFromSuperview];
self.videoViewController = nil;
Run Code Online (Sandbox Code Playgroud)

我目前的"解决方法"是简单地保留它,即使我不需要它.

有人可以解释为什么会发生这种情况以及如何解决它.

编辑:已解决 …

objective-c avfoundation ios4 ipad-2

6
推荐指数
2
解决办法
4905
查看次数

标签 统计

avfoundation ×1

ios4 ×1

ipad-2 ×1

objective-c ×1