iOS - Playback of recorded audio fails with OSStatus error -43 (file not found)

前端 未结 4 1436
-上瘾入骨i
-上瘾入骨i 2021-01-03 03:54

I set up an AVAudioRecorder instance the following way when my view loads:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
audioSession.deleg         


        
4条回答
  •  日久生厌
    2021-01-03 04:31

    AVEncoderBitRateKey is not working with AAC format encoding.So try this code.

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
    NSLog(@"%@", soundFileURL);
    
     NSDictionary *recordSettings = [NSDictionary 
                                            dictionaryWithObjectsAndKeys:
                                            [NSNumber numberWithInt:kAudioFormatMPEG4AAC],
                                            AVFormatIDKey,
                                            [NSNumber numberWithInt: AVAudioQualityMax],
                                            AVEncoderAudioQualityKey,
                                            [NSNumber numberWithInt: 1], 
                                            AVNumberOfChannelsKey,
                                            [NSNumber numberWithFloat:44100.0], 
                                            AVSampleRateKey,
                                            nil];
    NSError *error = nil;
    
    self.recorder = [[AVAudioRecorder alloc]
                     initWithURL:soundFileURL
                     settings:recordSettings
                     error:&error];
    self.recorder.delegate = self;
    
    if (error) {
        NSLog(@"error: %@", [error localizedDescription]);
        NSLog(@"error: %@", [error description]);
    } else {
        [self.recorder prepareToRecord];
    } 
    

    EDIT 1:

    OSStatus error -43 file not found is not a simulator issue. It's an error log, which shows your recording settings are not correct and required encoding format is not supported for the settings you have selected.

    When you get this error, you file will get created in the format as you given. But It will not initialize your audio recorder to start recording. If you have any doubt, then select the same settings, which you had in first question and record and try to play that. It won't record and play because of unsupported setting.

    So for a compressed encoding format, you can use a settings as I given above in my code. You can have .aac format for this settings. It will take 164KB per 10 seconds to record in aac format. For rest of the formats you have to try and figure out.

提交回复
热议问题