Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 01-25-2010, 03:20 AM   #3 (permalink)
Johanovski
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Johanovski is on a distinguished road
Default

Hi smasher!

Hm, I've tried following what your link said, but it doesn't work for me... What I've done before is to completely shutdown the sound manager when the application is interrupted, and restore again when it's restored. That way music sounds well (via AudioVideoPlayback), but sound doesn't get restored... This is how I'm doing it:

- In the AppDelegate class, when the applicationWillResignActive method is called an eaglView method named "shutDownAudio" is called, and when the applicationDidBecomeActive method is called another method named "reinstallAudio" is called. Here are that methods:

Code:
// EAGLView.m methods:

- (void) shutDownAudio
{
	if (sound) {
		[sharedSoundManager stopPlayingMusic];
	}
	
	if (menu) {
		[self netejaAudioMenu];
	}else{
		[self netejaAudioInterficie];
	}
	
	[sharedSoundManager shutdownSoundManager];

	sharedSoundManager = nil;
}

- (void) reinstallAudio
{
	if (!primerCop) {
                 [sharedSoundManager SingletonSoundManager];
	}
}
Code:
// mySoundManager class:

+ (SingletonSoundManager *)sharedSoundManager {
	
	// synchronized is used to lock the object and handle multiple threads accessing this method at
	// the same time
	@synchronized(self) {
		
		// If the sharedSoundManager var is nil then we need to allocate it.
		if(sharedSoundManager == nil) {
			// Allocate and initialize an instance of this class
			NSLog(@"SSM == nil");
			[[self alloc] init];
		}else {
			NSLog(@"SSM != nil");
		}


	}
	
	// Return the sharedSoundManager
	return sharedSoundManager;
}

- (id)init {
	NSLog(@"INIT SOUND");
	if(self = [super init]) {
		soundSources = [[NSMutableArray alloc] init];
		soundLibrary = [[NSMutableDictionary alloc] init];
		sourceLibrary = [[NSMutableDictionary alloc] init];
		musicLibrary = [[NSMutableDictionary alloc] init];
		
		// Set the default volume for music
		backgroundMusicVolume = 1.0f;
		
		// Set up the OpenAL
		BOOL result = [self initOpenAL];
		if(!result)	return nil;
		return self;
	}
	//[self release];
	return nil;
}

- (BOOL) initOpenAL {
	// Get the device we are going to use for sound.  Using NULL gets the default device
	device = alcOpenDevice(NULL);
	
	// If a device has been found we then need to create a context, make it current and then
	// preload the OpenAL Sources
	if(device) {
		//NSLog(@"INIT OPENAL SOUND");
		// Use the device we have now got to create a context "air"
		context = alcCreateContext(device, NULL);
		// Make the context we have just created into the active context
		alcMakeContextCurrent(context);
		// Pre-create 32 sound sources which can be dynamically allocated to buffers (sounds)
		NSUInteger sourceID;
		for(int index = 0; index < kMaxSources; index++) {
			//NSLog(@"new source:%d",index);
			// Generate an OpenAL source
			alGenSources(1, &sourceID);
			// Add the generated sourceID to our array of sound sources
			[soundSources addObject:[NSNumber numberWithUnsignedInt:sourceID]];
		}
		
		// Return YES as we have successfully initialized OpenAL
		//NSLog(@"YES!");
		return YES;
	}
	// Something went wrong so return NO
	//NSLog(@"NO!");
	return NO;
}

- (void) shutdownSoundManager {
	@synchronized(self) {
		if(sharedSoundManager != nil) {
			[self dealloc];
		}
	}
}

- (void)dealloc {
	// Loop through the OpenAL sources and delete them
	for(NSNumber *numVal in soundSources) {
		NSUInteger sourceID = [numVal unsignedIntValue];
		alDeleteSources(1, &sourceID);
	}
	
	// Loop through the OpenAL buffers and delete 
	NSEnumerator *enumerator = [soundLibrary keyEnumerator];
	id key;
	while ((key = [enumerator nextObject])) {
		NSNumber *bufferIDVal = [soundLibrary objectForKey:key];
		NSUInteger bufferID = [bufferIDVal unsignedIntValue];
		alDeleteBuffers(1, &bufferID);		
	}
	
	// Release the arrays and dictionaries we have been using
	[soundLibrary release];
	[soundSources release];
	[sourceLibrary release];
	[musicLibrary release];
	
	// Disable and then destroy the context
	alcMakeContextCurrent(NULL);
	alcDestroyContext(context);
	
	// Close the device
	alcCloseDevice(device);
	
	sharedSoundManager = nil;
	
	[super dealloc];
}
The music is restored well, but the sound never plays again after the app has become interrupted... Any clue about this?

Thanks in advance!


I've read something about audioSessions, but I don't understand where it have to be set, and no clue on how to use the listenerCallback function, or anything about this... I'm really unable to understand how to deal with that sound problem! Anyone can help me? :S

Last edited by Johanovski; 01-26-2010 at 06:17 AM.
Johanovski is offline   Reply With Quote
 

» Advertisements
» Online Users: 466
17 members and 449 guests
chemistry, David-T, DavidSmith, Duncan C, Free App Monster, G-Power, Hassasin, iconomania, jimmyon122, LooN3y, mediaspree, n00b, Objective Zero, raheel, stanny, timle8n1, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,437
Threads: 94,026
Posts: 402,591
Top Poster: BrianSlick (7,978)
Welcome to our newest member, DavidSmith
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:27 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.