Search code examples
objective-cavaudioplayeravaudiorecorder

Playing a file recorded with AVAudioRecorder on AVAudioPlayer


Right now I'm trying to play a .wav file that is first recorded with a AVAudioRecorder, and then playing this sound with a AVAudioPlayer. This seems simple enough, but i want the AVAudioRecorder PAUSED, not stopped. That is the problem, for some reason the AVAudioPlayer refuses to play a file that is opened in the recorder. So this works:

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
[recorder record];

*record for some time*

[recorder stop];

player = [[AVAudioPlayer alloc] initWithContentsOfURL:[self copySoundFileURL] error:nil];
[player play];

But i want it to work when i call it like this:

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
[recorder record];

*record for some time*

[recorder pause];

player = [[AVAudioPlayer alloc] initWithContentsOfURL:[self copySoundFileURL] error:nil];
[player play];

(these are ofcourse examples)

Basically my question is if anyone knows a way to do either of these:

  1. Play a file that is open in the recorder.
  2. Stop the recorder, play the file and then resume recording on the same file (not losing the previously recorded stuff).

Any information/thoughts are welcome!!


Solution

  • The only way I could find to fix this is by merging 2 wav files. some more information on this is found in another one of my questions: NSURL returns Invalid Summary when merging WAV files . This is not 100% correct (hence the question) but it's a start for people that want some information about this.