I'm having (another) strange audio problem. I'm using SimpleAudioEngine to play a looped background music during game play. When a user toggles the "pause" button, the sound stops. It is supposed to resume playing when the game starts back up. I don't know what I changed recently, but it used to work. Now, the background music plays the first time, but never resumes after it's paused. Here's what I'm doing:
- (void) init {
// normal init stuff
if (myGame.soundFxEnabled) { // myGame refernces my game data class
SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
[sae preloadBackgroundMusic:@"bgmusic.caf"];
if (sae.willPlayBackgroundMusic) {
sae.backgroundMusicVolume = myGame.soundFxVolume;
}
}
}
- (void) togglePower:(id)sender {
if (toggleOn != YES) {
[power selected];
toggleOn = YES;
gameClockTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateGameClock) userInfo:nil repeats:YES] retain];
if (myGame.soundFxEnabled) {
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"bgmusic.caf"];
}
} else {
[power unselected];
toggleOn = NO;
[gameClockTimer invalidate];
if (myGame.soundFxEnabled) {
[[SimpleAudioEngine sharedEngine] pauseBackgroundMusic];
}
}
Seems pretty straightforward, and it was working for me until recently. I don't know what changed. Here's some of the Denshion related messages in the console:
// pre-loading stuff from init
// the other sounds are coming from another layer's init
Denshion: Checking for other audio
Denshion: Other audio is not playing audio will be exclusive
Denshion: channel def 0 0 30 0
Denshion: loading new or different background music file bgmusic.caf
Denshion: Loading openAL buffer 0 whistle1.caf
Denshion: size 167936 frequency 44100 format 4353 166846464
Denshion: Loading openAL buffer 1 whistle2.caf
Denshion: size 96256 frequency 44100 format 4353 166846464
Denshion: Loading openAL buffer 2 cheer.caf
Denshion: size 419840 frequency 44100 format 4353 177954816
// switch turned on
Denshion: request to play current background music file
// nothing in the console when the pause method gets called
// but the audio does stop correctly
// switch turned back on
// calls the same request, but nothing plays
Denshion: request to play current background music file
This happens in the Simulator and on the device (both running 3.1). I'm using cocos2d 0.8.1 with the CocosDenshion files from 0.8.2
Is there a retain I'm missing somewhere, or is there something I'm doing wrong?