Record AVAudioPlayer output using AVAudioRecorder

后端 未结 4 582
说谎
说谎 2021-01-14 14:46

In my app the user plays a sound by pressing a button. There are several buttons which can be played simultaneously. The sounds are played using AVAudioPlayer instances. I w

4条回答
  •  有刺的猬
    2021-01-14 15:08

    Was facing the same problem. Solved the problem by setting the AVAudioSession category to AVAudioSessionCategoryPlayback mode. This is my working code:

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    audioSession.delegate = self;
    [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
    [audioSession setActive: YES error: nil];
    

    Also make sure that the audio recording has been finished successfully by implementing:

       -(void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
    {
        NSLog(@"Recording success:%@",flag ? @"YES" : @"NO");
    }
    

    And check that you have added

    in your interface declaration.

提交回复
热议问题