Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
alarm bug?

also... is there a bug with the Clock app's alarm concerning interruption of sound?

i am having difficulty reactivating sound after executing my -(void)endInterruption delegate method. the sound methods are firing but there is just no sound being produced from the device. to make sure i wasn't crazy i just tested having an alarm go off while playing a few other games i purchased from the app store and the same issue occurs.

could this just be my device?

[EDIT] it seems that sounds produced with AVAudioPlayer are not affected, only OpenAL.

Code:
void interruptionListenerCallback (void *inUserData, UInt32 interruptionState) 
	{
	OpenALSoundManager *soundMgr = (OpenALSoundManager *) inUserData;

	if (interruptionState == kAudioSessionBeginInterruption) 
		{		
		[soundMgr beginInterruption];
		soundMgr.interrupted = YES;
		}
		 
	else if ((interruptionState == kAudioSessionEndInterruption) && soundMgr.interrupted)
		{
		[soundMgr endInterruption];
		soundMgr.interrupted = NO;
		}
	}
	
- (id)init
	{
	self = [super init];		
	
	if (self != nil) 
		{		
		OSStatus status = AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, self);
				
		self.soundDictionary = [NSMutableDictionary dictionary];
		self.soundEffectsVolume = 1.0;
		self.backgroundMusicVolume = 1.0;		
		[self endInterruption];
		}
	
	return self;
	}

-(BOOL)startupOpenAL
	{
	ALCcontext *context = NULL;
	ALCdevice *device = NULL;
	device = alcOpenDevice(NULL);

	if (!device) return NO;
		
	context = alcCreateContext(device, NULL);

	if (!context) return NO;
	
	alcMakeContextCurrent(context);
	return YES;	
	}

- (void)shutdownOpenAL
	{
	ALCcontext *context = NULL;
	ALCdevice *device = NULL;
	context = alcGetCurrentContext();
	device = alcGetContextsDevice(context);
	alcDestroyContext(context);
	alcCloseDevice(device);
	}
	

#pragma mark -
#pragma mark Audio Session Management

- (void)beginInterruption
	{
	[self stopBackgroundMusic];
	[self clearAllSoundsFromMemory];
	[self shutdownOpenAL];
	
	if (!self.isiPodAudioPlaying)
		{
		UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		AudioSessionSetActive(YES);
		}
		else
		{
		UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		AudioSessionSetActive(YES);
		}
	
	AudioSessionSetActive(NO);
	}

- (void)endInterruption
	{
	[self setupAudioCategorySilenceIpod:NO];
	[self startupOpenAL];	
	
	AudioSessionSetActive(YES);
	}

- (void)setupAudioCategorySilenceIpod:(BOOL)silenceIpod;
	{
	UInt32 audioIsAlreadyPlaying;
	UInt32 propertySize = sizeof(audioIsAlreadyPlaying);
	
	OSStatus err = AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);	
	
	if (audioIsAlreadyPlaying && !silenceIpod)
		{
		self.isiPodAudioPlaying = YES;
		UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);		
		}
		else
		{
		self.isiPodAudioPlaying = NO;
		UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;
		AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);		
		}		
	}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.