AVAudioRecorder Won't Record On Device

后端 未结 5 1709
失恋的感觉
失恋的感觉 2021-01-02 22:28

This is my method:

-(void) playOrRecord:(UIButton *)sender {
    if (playBool == YES) {
        NSError *error = nil;
        NSString *filePath = [[NSBundle         


        
5条回答
  •  日久生厌
    2021-01-02 23:03

    I had the exact same problem. It turns out I was bumping up against an incorrectly generated path statement. The AVAudioRecorder initialized fine - and without incident - but iOS simply would not allow me to write to it. Why? Check it out:

        /* The following code will fail - why? It fails because it is trying to write some path that is NOT accessible by
        this app.
    NSString *recordedAudioPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) 
                                    objectAtIndex:0] 
                                   stringByAppendingString:@"recorded.caf"];
     */
    // Correction:
    NSString *recordedAudioPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) 
                                   objectAtIndex:0];
    
    recordedAudioPath = [recordedAudioPath stringByAppendingPathComponent:@"recorded.caf"];
    NSURL *recordURL = [NSURL fileURLWithPath:recordedAudioPath];
    

    This makes complete sense now. Thanks for steering me in the right direction.

提交回复
热议问题