![](/img/trans.png)
[英]Error Domain=AVFoundationErrorDomain Code=-11821 "Cannot Decode"
[英]Error Domain=AVFoundationErrorDomain Code=-11814 “Cannot Record”
它不斷給我錯誤:
錯誤域=AVFoundationErrorDomain 代碼=-11814“無法記錄”
我不確定是什么問題? 我正在嘗試在拍攝照片后計數器達到 1 時立即錄制聲音。
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];
}
}
這個錯誤是因為你使用了模擬器,需要使用設備
問候
確保只有一個AVCaptureSession
實例正在運行。
讓您的設備在“設置 > 常規 > 限制”下限制相機訪問也會給您這個錯誤。
我在 Mac 上使用 Mac Catalyst 應用程序嘗試 AVFoundation 時遇到了同樣的錯誤。 顯然,這是記錄在案的和預期的行為:
https://forums.developer.apple.com/thread/124652#389519
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture
此問題的行為符合預期。 我們確實記錄了我們沒有在 Catalyst 模式下列出設備。 請參閱在 macOS 中運行的重要 iPad 應用程序無法使用 AVFoundation Capture 類。 這些應用程序應該使用 UIImagePickerController 進行照片和視頻捕獲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.