Sunday, 18 August 2013

Strange behavior of background music in cocos2d iOS

Strange behavior of background music in cocos2d iOS

I am using cocos2d v2 and experiencing a very strange behaviour.
I have a couple of audio tracks which are supposed to be played as
background music one after another. But I noticed when these tracks are
playing in background, any updates on screen (rendering) isn't working.
For instance I added a new sprite marker after every new track but nothing
shown on screen until all the tracks are done playing. I also tried
displaying track # using CCLABELBMFont but that also didn't show anything
on screen until all tracks are finished playing.
Here's the code:
NSString *keyString;
CCARRAY_FOREACH([[GameManager sharedGameManager] _musicItems], keyString){
CCSprite *marker = [CCSprite spriteWithSpriteFrameName:@"marker.png"];
[marker setPosition:ccp(100 * count, 200)];
[spriteBatchNode addChild:marker z:100];
if ([[[GameManager sharedGameManager] _soundEngine]
isBackgroundMusicPlaying]) {
int waitCycles = 0;
while (waitCycles < AUDIO_MAX_WAITTIME) {
[NSThread sleepForTimeInterval:0.1f];
if (![[[GameManager sharedGameManager] _soundEngine]
isBackgroundMusicPlaying]) {
break;
}
waitCycles += 1;
}
}
//play sound file
CCLOG(@"Playing Sound file: %@", keyString);
[[GameManager sharedGameManager] playBackgroundTrack:keyString];
}
Anyone has ideas why it's happening?

No comments:

Post a Comment