Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Domain=AVFoundationErrorDomain Code=-11814 "Cannot Record"

It keeps on giving me the error:

Error Domain=AVFoundationErrorDomain Code=-11814 "Cannot Record"

I am not sure what the problem is? I am trying to record the sound right when the counter reaches 1 after a picture is taken.

static int counter;
//counter will always be zero it think unless it is assigned.


if (counter == 0){

dispatch_async([self sessionQueue], ^{
    // Update the orientation on the still image output video connection before capturing.
    [[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:[[(AVCaptureVideoPreviewLayer *)[[self previewView] layer] connection] videoOrientation]];

    // Flash set to Auto for Still Capture
    [AVCamViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];

    // Capture a still image.
    [[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {

        if (imageDataSampleBuffer)
        {//[AVCaptureSession snapStillImage];
            NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
            UIImage *image = [[UIImage alloc] initWithData:imageData];
            [[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
        }
        NSLog(@"i");
    }];
});

    if (!_audioRecorder.recording)
{
   //start recording as part of still image

    _playButton.enabled = NO;
    _stopButton.enabled = YES;
    [_audioRecorder record];

    for(int i=0;i<1000;i++)
    {
        //do nothing just counting
    }

    //stop the recording
}

}

else if (counter == 1)

{
    [self recordForDuration:5];
}


}
like image 806
Akbapu Avatar asked Jun 12 '14 05:06

Akbapu


3 Answers

Make sure there is only one instance of AVCaptureSession running.

like image 75
Srinija Avatar answered Nov 06 '22 19:11

Srinija


This error is because you use an emulator, you need use an device

Regards

like image 24
Christian Cruz Avatar answered Nov 06 '22 20:11

Christian Cruz


Having your device restrict the camera access under "Settings > General > Restrictions" will also give you this error.

like image 22
mtoio Avatar answered Nov 06 '22 21:11

mtoio