I have the same problem. I use AVPlayer to play songs (previous recordings that I used AVAudioRecord for). However, I found that as soon as I used AVPlayer, I could no longer use AVAudioRecorder. After some searching, I found that as long as AVPlayer is created in memory and played at least once (which usually happens immediately after its creation), AVAudioRecorder will not record. However, once AVPlayer is canceled, AVAudioRecorder can then record again. It looks like AVPlayer supports some kind of connection that AVAudioRecorder requires, and it's greedy ... it won't let it go until you get it out of your cold dead hands.
This is the solution I found. Some people claim that creating an instance of AVPlayer takes too much time to continue to break and configure backups. However, it is not. Activating AVPlayer is actually pretty trivial. An instance of AVPlayerItem is also created. What is not trivial is downloading AVAsset (or any of its subclasses). You really want to do this only once. They should use this sequence:
- Download AVAsset (for example, if you are loading from a file, use AVURLAsset directly or add it to AVMutableComposition and use this) and save the link to it. Do not let this go until you are done with it. Downloading is what takes all the time.
- Once you're ready for the game: create AVPlayerItem with your asset, then AVPlayer with AVPlayerItem and play it. Do not keep the link to AVPlayerItem, AVPlayer will save the link to it, and you will not be able to reuse it with another player.
- Once this happens, immediately destroy AVPlayer ... release it, set its var to zero, whatever you do. **
- Now you can record. AVPlayer does not exist, so AVAudioRecorder can do its best.
- When you are ready to play again, recreate an instance of AVPlayerItem with the resource you already downloaded and AVPlayer. Again, this is trivial. The asset is already loaded, so there should be no delay.
** Note that killing AVPlayer may take more than just letting go of it and setting var to nil. Most likely, you also added a periodic time observer to track playback progress. When you do this, you will get back an opaque object that you must hold onto. If you do not remove this item from the player and release it / set it to zero, AVPlayer will not delete it. It looks like Apple is creating a deliberate save cycle, which you must manually chop. Therefore, before destroying AVPlayer, you need (example):
[_player removeTimeObserver:_playerObserver]; [_playerObserver release];
As an extra note, you can also set up NSNotifications (I use one to determine when a player completed the game) ... don't forget to delete them as well.
Aaron hayman
source share