Strange. So I set it up as follows. I call prepare scene change, which will fade out the BG music, then cue up a new BG Music. I then explicitly call startBGMusic and expect it to work. Sadly no - when trying to go from front end to back end (kill an existing BGM track) console spits out:
Denshion::CDLongAudioSource - Loading new audio source GameResources/Audio/BE/BGAmbience.caf
2010-12-30 15:37:56.072 MyGame[16981:307] Denshion::CDLongAudioSource - Error initialising audio player: Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)"
-(void)loadFrontEnd:(id)sender{
SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
[sae preloadBackgroundMusic: feMusic ];
if (sae.willPlayBackgroundMusic) {
sae.backgroundMusicVolume = 0.85f;
}
}
bgMusic = feMusic;
}
-(void)loadBackEnd:(id)sender{
SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
[sae preloadBackgroundMusic: beMusic ];
if (sae.willPlayBackgroundMusic) {
sae.backgroundMusicVolume = 0.85f;
}
}
bgMusic = beMusic;
}
// PLAYBACK METHODS
-(void)startBGMusic:(float)fadeInTime
{
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:bgMusic ];
}
-(void)prepareSceneChange:(int)toScene fadeTime:(float)fadeOutTime
{
// if there is no background music playing it will simply call the load front end stuff.
SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
id actionCallFuncN;
if (toScene == 1) {
// to change to front end
actionCallFuncN = [CCCallFuncN actionWithTarget:self selector:@selector(loadFrontEnd:)];
}
else {
// is back end
actionCallFuncN = [CCCallFuncN actionWithTarget:self selector:@selector(loadBackEnd:)];
}
// so, will now fade out whatever background track is playing, and after that, call the appropriate action.
if (![sae isBackgroundMusicPlaying]) {
CDLOG(@">> Background music is not playing");
CDLongAudioSource *player = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Left]; // default BGM channel
[[CCActionManager sharedManager] addAction: actionCallFuncN target:player paused:NO];
} else {
//Fade out
CDLongAudioSource *player = [[CDAudioManager sharedManager] audioSourceForChannel:kASC_Left]; // default BGM channel
CDLongAudioSourceFader* fader = [[CDLongAudioSourceFader alloc] init:player interpolationType:kIT_Exponential startVal:player.volume endVal:0.0];
[fader setStopTargetWhenComplete:YES]; // this technically just pauses the track. 'stopping' will release it.
//Create a property modifier action to wrap the fader
CDXPropertyModifierAction* action = [CDXPropertyModifierAction actionWithDuration:fadeOutTime modifier:fader];
[fader release];//Action will retain
[[CCActionManager sharedManager] addAction:[CCSequence actions:action, actionCallFuncN, nil] target:player paused:NO];
}
}
Any ideas? NOTE: It throws the error when trying to preloadBackgroundMusic in the loadBackEnd: method. (i.e. it worked for front end because nothing was previously loaded)