Search code examples
avaudioplayeravaudiorecorder

AVAudiorecorder & AVAudioPlayer not always playing sound


I have a view in which I record sound using AVAudiorecorder and then it save to the document directory. And from another View I am playing the sound using AVAudioplayer from document directory. But the strange behavior is that AVaudioPlayer always not playing the sound, but in sometimes it play sound.


Solution

  • Yes the problem is solved, I have to reinitialize the audio session to playbackCategory using the following code

    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);AudioSessionSetActive(true); 
    

    Now it can always play the sound.