Not forcing AudioStream to initialize
Monkey Targets Forums/iOS/Not forcing AudioStream to initialize
| ||
Hi Currently Monkey on initialize starts audio device (or whatever it is) and you can see in debug something like that: AudioStreamBasicDescription: 2 ch, 44100 Hz, 'lpcm' (0x00000C2C) 8.24-bit little-endian signed integer, deinterleaved This happens even in programs that don't use audio at all (like clock example). The problem is that this behavior stops iPod playback and we can't make programs that won't use music (or will mute music if iPad is playing something) and let player/user listed to iPod program. Unfortunately, such behavior is one of requirements from top iOS publishers. Can we do something about it? cheers Roman |
| ||
We can use this function to check if iPod is playing anything: bool isIPODMusicPlaying () { BOOL isPlaying = NO; MPMusicPlayerController* iPodMusicPlayer = [MPMusicPlayerController iPodMusicPlayer]; if (iPodMusicPlayer.playbackState == MPMusicPlaybackStatePlaying) { isPlaying = YES; } #ifndef NDEBUG NSLog(@"Music is %@.", isPlaying ? @"on" : @"off"); #endif return isPlaying; } (don't forget to add MediaPlayer framework to your project). From what I reengineered it looks like Monkey initialize audio in didFinishLaunchingWithOptions with this line: if( !alcMakeContextCurrent( alcContext ) ) RuntimeError( "alcMakeContextCurrent failed" ); so we would need to modify this line to check if iPod is playing music, and if so, not make context current. Later, whenever we call Play sfx/music funtions we would need to check again if music is playing and if no if current context is Monkey context. |
| ||
OK, so it's easy to not turn sound engine on while iPod is playing, but it's black magic so far to turn off music engine after your app has been suspended, iPod music turned on, and your app resumed (in this case your app resumes audio and kills iPod playback). |
| ||
There is hope for us Monkeys... I found solution (thanks to www.ovogame.com). I'll send the code changes to Mark after giving it a bit more testing. |
| ||
Awesome, good work! :) I used to comment out the 3 "alcMakeContextCurrent" etc. calls to fix this (in a game that doesn't use sound), but will be great to have this support already in Monkey. |
| ||
OK, I finished the job. Files that changed have been sent to Mark. Hopefully he can add it to next release. |