iPhone 4 iOS 7视频录制中的黑屏?

时间:2013-12-13 12:02:10

标签: ios7 recording

我有一个使用前置摄像头和麦克风录制视频的应用。我在带有iOS 6的iPhone 4S,iPad 2 iPhone 5和带iOS 7的iPhone 5S上试用了它,视频被正确录制和播放。

但是在带有iOS 7.0.4的iPhone 4上,有时会出现带有音频的黑屏,有时会有视频,但没有任何音频。

当出现此错误时,iPhone上的任何其他应用程序将仅录制黑屏或录制没有音频的视频。我必须重新启动iPhone 4才能再次尝试录制。

这是iOS 7上的错误,还是我的代码有问题?有没有人经历过这个?

这是录音代码:

- (void)setupSession {

    AVCaptureSession *session = [[AVCaptureSession alloc] init];

    [session beginConfiguration];

    // Recording in low resolution to boost up video capturing on lower-end devices
    if ([session canSetSessionPreset:AVCaptureSessionPresetMedium]) {
        session.sessionPreset = AVCaptureSessionPresetMedium;
        NSLog(@"%@", session.sessionPreset);
    }

    if (!self.frontCamera || !self.microphone) {
        NSLog(@"Unable to start recording session");
        return;
    }

    // Adding camera capturing input
    NSError *error;
    AVCaptureDeviceInput *cameraInput = [AVCaptureDeviceInput deviceInputWithDevice:self.frontCamera
                                                                              error:&error];
    if (!cameraInput) {
        NSLog(@"Couldn't retrieve camera input: %@", [error localizedDescription]);
        return;
    }

    // Adding audio capturing input
    error = nil;
    AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:self.microphone
                                                                             error:&error];
    if (error) {
        NSLog(@"Couldn't retrive camera input: %@", [error localizedDescription]);
        return;
    }

    if ([session canAddInput:cameraInput] && [session canAddInput:audioInput]) {
        [session addInput:cameraInput];
        [session addInput:audioInput];
    } else {
        NSLog(@"Session input could not be added");
    }

    // Adding movie file output
    AVCaptureMovieFileOutput *movieFileOutput = [[AVCaptureMovieFileOutput alloc] init];

    if ([session canAddOutput:movieFileOutput]) {
        [session addOutput:movieFileOutput];
        self.movieFileOutput = movieFileOutput;
    } else {
        return;
        NSLog(@"Session output could not be added");
    }

    AVCaptureConnection *videoConnection = movieFileOutput.connections[0];
    if ([videoConnection isVideoOrientationSupported]) {
        videoConnection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
    }

    // Listen for notifications
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(receivedCaptureSessionNotification:)
                                                 name:nil
                                               object:session];

    _session = session;

    [session commitConfiguration];

    self.canRecord = YES;
}`

这是我的dealloc:

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:AVPlayerItemDidPlayToEndTimeNotification
                                                  object:self.session];

    if ([self.session isRunning]) {
        for(AVCaptureInput *input1 in self.session.inputs) {
            [self.session removeInput:input1];
        }

        for(AVCaptureOutput *output1 in self.session.outputs) {
            [self.session removeOutput:output1];
        }

    [self.session stopRunning];
    }
    self.session=nil;

    NSLog(@"gamerecording dealloc'd");

}

我在dealloc上记录了我的会话输入,并且始终列出了麦克风和前置摄像头。

如果需要更多信息,我可以加入。

0 个答案:

没有答案