OpenAL Sounds stop after lock or call
Hi all
I've just spotted a problem with a simple sound engine I've written. It uses OpenAL for sound effects and AVAudioPlayer for background music. The sound effects play fine when the game starts, but if a call comes in, or I lock the phone and then go back to the game, there is no sound.
Does anyone know how to fix this.
Cheers
MikeD
I've just spotted a problem with a simple sound engine I've written. It uses OpenAL for sound effects and AVAudioPlayer for background music. The sound effects play fine when the game starts, but if a call comes in, or I lock the phone and then go back to the game, there is no sound.
Does anyone know how to fix this.
Cheers
MikeD
MikeD Wrote:I've just spotted a problem with a simple sound engine I've written. It uses OpenAL for sound effects and AVAudioPlayer for background music. The sound effects play fine when the game starts, but if a call comes in, or I lock the phone and then go back to the game, there is no sound.
Register your sound class with UIApplicationWillResignActiveNotification and UIApplicationDidBecomeActiveNotification. Those get sent when a phone call comes in and is finished.
Code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:@"UIApplicationWillResignActiveNotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:@"UIApplicationDidBecomeActiveNotification" object:nil];Then in the callbacks you basically shut down and restart the entire sound system. I free all my sounds, buffers, audio queues, audio session, etc. Then re-initialize them all after the call is over. Pain in the ass, but the iPhone sound system is so twitchy it's the only way (I've found) to keep the whole thing running.
Code:
- (void) applicationWillResignActive:(NSNotification *)notification
{
[self pauseSoundSystem];
}
- (void) applicationDidBecomeActive:(NSNotification *)notification
{
[self restartSoundSystem];
}EDIT:
Oh, I forgot. There's also times where the sound system can get interrupted but your app *doesn't* change it's active state (so no notifications get sent). You'll want to register an Audio Session with an interruption callback to catch these.
Code:
AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self); // In your init code
void interruptionListenerCallback(void *inUserData, UInt32 interruptionState)
{
MySoundClass *controller = (MySoundClass *)inUserData;
if (interruptionState == kAudioSessionBeginInterruption)
{
[controller pauseSoundSystem];
}
else if (interruptionState == kAudioSessionEndInterruption)
{
[controller restartSoundSystem];
}
}
Thanks Bachus, that's great info which I'll try out.
I appreciate the quick response.
MikeD
I appreciate the quick response.
MikeD
Just in to finish this thread off, the problem was actually a bug with SDK Beta 5. Since GM the problem has gone away 
MikeD

MikeD
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Slowdown while playing many OpenAL sounds and accessing AVAudioPlayer.playing | Rasterman | 6 | 4,675 |
Aug 31, 2010 09:46 PM Last Post: headkaze |
|
| New Game Finished Warlords: Call To Arms | kendric | 2 | 2,146 |
Apr 5, 2010 01:45 PM Last Post: kendric |
|
| Call for beta testers for FaceRace | WeHeartGames | 0 | 1,757 |
Aug 28, 2009 07:16 AM Last Post: WeHeartGames |
|

