I need to have have audio (a lecture etc.) recording on iPhone and directly playing back through the headphones.
I have code that works - most of the time!
I set up my AVAudioSession
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
I set up my player and recorder, both pointing to the same URL.
audioRecorder = [[AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSettings error:&error];
//set up audio playing audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:&error];
I prepare to play and record
[audioRecorder prepareToRecord]; [audioPlayer prepareToPlay];
Everything proceeds well for a while. Then suddenly, the player stops, and its current time goes to zero.
It doesn't look like its getting dealloc'ed, since I can proceed to play the recorded sound just fine from the start position. The stopping occurs seemingly randomly, at different times each time.
Anyone have any suggestions as to what the problem is or how to debug?
Thanks in advance!