OpenAL and AVAudioPlayer in the Simulator
I have been playing sounds with my OpenAL audio player code for a while now (in the simulator and on the device). I am trying to add playing capabilities via AVAudioPlayer. When I run on the device, I can play sounds via the AVAudioPlayer member, or via my existing OpenAL sound play calls (which I happened to discover via dumb luck after getting frustrated with the simulator). When I run on the simulator, if I play a sound with AVAudioPlayer, my OpenAL sounds no longer play (and I detect no errors). If I don't play a sound via AVAudioPlayer, my OpenAL sounds still work in the simulator. Any thoughts? I have 2.2.1 SDK.
Thanks in advance!
- Jason
Thanks in advance!

- Jason
More info: I play the sound with AVAudioPlayer when my app launches. I noticed if I get into game fast enough some of my OpenAL sounds do play during the duration of the AVAudioPlayer sound playing. It's like something is being turned off/disabled after the AVAudioPlayer playback finishes.
This turned out to be an AVAudioPlayer bug (which clobbers OpenAL audio). Steve Oldmeadow's CocosDenshion (sound engine) code provides a workaround until Apple fixes it. I think I'm switching to CocosDenshion (I'm already using cocos2d).
#if TARGET_IPHONE_SIMULATOR
CCLOG(@"Denshion: workaround for OpenAL clobbered audio issue");
//This is a workaround for an issue in the 2.2 and 2.2.1 simulator. Problem is
//that OpenAL audio playback is clobbered when an AVAudioPlayer stops. Workaround
//is to keep the player playing on an endless loop with 0 volume and then when
//it is played again reset the volume and set loop count appropriately.
player.numberOfLoops = -1;
realBackgroundMusicVolume = player.volume;
player.volume = 0;
[player play];
#endif
#if TARGET_IPHONE_SIMULATOR
CCLOG(@"Denshion: workaround for OpenAL clobbered audio issue");
//This is a workaround for an issue in the 2.2 and 2.2.1 simulator. Problem is
//that OpenAL audio playback is clobbered when an AVAudioPlayer stops. Workaround
//is to keep the player playing on an endless loop with 0 volume and then when
//it is played again reset the volume and set loop count appropriately.
player.numberOfLoops = -1;
realBackgroundMusicVolume = player.volume;
player.volume = 0;
[player play];
#endif
Audio in the simulator is just plain broken. That Cocos workaround is likely a red herring, since any audio coming from anywhere on the system affects the simulator in a similar ways. The only real "fix" is to never play audio in the simulator.
Curiously, although I'm using AVAudio and now OpenAL too, I've found it all works perfectly, all the time: not a single hitch. I've upgraded all to 3.0, so I don't know if it would have been a problem with earlier versions...
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| AVAudioPlayer returning -43 | FlamingHairball | 4 | 6,207 |
Aug 31, 2011 10:29 AM Last Post: FlamingHairball |
|
| Slowdown while playing many OpenAL sounds and accessing AVAudioPlayer.playing | Rasterman | 6 | 4,691 |
Aug 31, 2010 09:46 PM Last Post: headkaze |
|
| AVAudioPlayer | kae_ | 8 | 7,330 |
Aug 10, 2010 04:13 AM Last Post: kae_ |
|
| performance bug in AVAudioPlayer | captainfreedom | 2 | 3,496 |
Aug 4, 2010 12:03 PM Last Post: captainfreedom |
|
| AVAudioPlayer stutters the game when changing song | AdrianM | 0 | 3,296 |
May 13, 2010 03:59 PM Last Post: AdrianM |
|

