Seemingly random file corruption using AVAudioRecorder (Sometimes the file can't be played back) - iOS

后端 未结 1 2051
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 14:28

In an app I\'m currently developing, I\'ve more or less hit a brick wall. In the application you can enter a view which lists all locally saved audio files in a standard table v

1条回答
  •  被撕碎了的回忆
    2021-02-05 15:08

    Note: Since the OP is inactive for some days and I guess this question should be answered for public's future reference, thus I post this answer.

    The AVAudioSession has to be obtained before start recording.

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
    if(err){
       NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
       return;
    }
    err = nil;
    [audioSession setActive:YES error:&err];
    if(err){
       NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
       return;
    }
    

    Reference: https://stackoverflow.com/a/9706731/188331

    0 讨论(0)
提交回复
热议问题