Music whilst running app

Monkey Targets Forums/iOS/Music whilst running app

siread(Posted 2012) [#1]
I seem to remember reading something about this but I can't find it. I have had a lot of customers wanting to hear their own music (iTunes, Spotify or whatever) whilst playing the game. Is this anything we can do to allow this? Normally the music gets faded out as you start or even switch to the Monkey app.


anawiki(Posted 2012) [#2]
It was me... It was me :) Now there are two of us. I can send you mojo changes later, and you can nag Mark to make them more official, because what he did after my nagging was just partial implementation of what I asked for.


York(Posted 2012) [#3]
Hey siread and anawiki,

I also miss this feature. Now there are three ;)
Is there any chance that you can upload this changes?


Fred(Posted 2012) [#4]
Search for didFinishLaunchingWithOptions in Main.mm in target/ios
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions{

Then look for this:
ALCdevice *alcDevice=alcOpenDevice( 0 );
if( !alcDevice ) RuntimeError( "alcOpenDevice failed" );

Add these lines right after:
AudioSessionInitialize(NULL, NULL, NULL,NULL);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		
UInt32 allowMixing = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);

original code continues with this:
ALCcontext *alcContext=alcCreateContext( alcDevice,0 );
if( !alcContext ) RuntimeError( "alcCreateContext failed" );
if( !alcMakeContextCurrent( alcContext ) ) RuntimeError( "alcMakeContextCurrent failed" );
}
return YES;
}


Add also this Import in Main.h

#import <AudioToolbox/AudioToolbox.h>



York(Posted 2012) [#5]
Hey cool,

thanks for your help.


siread(Posted 2012) [#6]
Yeah, thanks Fred. I'll try this out in my next update. :)


siread(Posted 2012) [#7]
Worked like a charm! Thanks.


siread(Posted 2012) [#8]
I noticed that the above code overrides the physical mute button on certain devices (ie muting the device has no effect on your Monkey app sounds). To rectify this use kAudioSessionCategory_UserInterfaceSoundEffects instead of kAudioSessionCategory_MediaPlayback.

AudioSessionInitialize(NULL, NULL, NULL,NULL);
UInt32 sessionCategory = kAudioSessionCategory_UserInterfaceSoundEffects;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
		
UInt32 allowMixing = true;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(allowMixing), &allowMixing);