Is there any method to fade sounds like iPod music when the user want to use your app?
Thanks.
Is there any method to fade sounds like iPod music when the user want to use your app?
Thanks.
If you configure and activate certain audio session types where your app will play sounds (see Apple's Audio Session reference), the OS will fade out the sound from any background apps currently using the audio output, so that your app will have the resources available.
Some quick sample code that will do this (call from somewhere when your app becomes active or launches & don't forget to link to AVFoundation framework):
#import <AVFoundation/AVAudioSession.h>
// ...
- (void)setupAudioSession
{
NSError* error = nil;
AVAudioSession* session = [AVAudioSession sharedInstance];
// see documentation for delegate methods you should handle
[session setDelegate:self];
// This category will duck and cancel background category, but can be configured
// later for mixing if you want (making it pretty versatile); see documentation
// on categories for other options
if( ![session setCategory:AVAudioSessionCategoryPlayback error:&error] ) {
// handle error
NSLog(@"Error setting audio category: %@, %@", error, [error userInfo]);
}
if( ![session setActive:YES error:&error] ) {
// handle error
NSLog(@"Error setting audio session as active: %@", error);
}
}