Akbapu
Akbapu

Reputation: 779

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];
}


}

Upvotes: 13

Views: 11354

Answers (5)

Hellomik U
Hellomik U

Reputation: 563

I can be related with camera, You forget get info about device camera

Upvotes: 0

Jan Ehrhardt
Jan Ehrhardt

Reputation: 405

I ran into the same error when I was trying AVFoundation on a Mac, using a Mac Catalyst app. That is documented and intended behaviour, apparently:

https://forums.developer.apple.com/thread/124652#389519

https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture

This issue behaves as intended. We do document that we are not listing devices in Catalyst mode. See Important iPad apps running in macOS cannot use the AVFoundation Capture classes. These apps should instead use UIImagePickerController for photo and video capture.

Upvotes: 0

Srinija
Srinija

Reputation: 317

Make sure there is only one instance of AVCaptureSession running.

Upvotes: 4

user4181645
user4181645

Reputation:

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

Upvotes: 2

Christian Cruz
Christian Cruz

Reputation: 668

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

Regards

Upvotes: 12

Related Questions