cocos2d music preload

948 views Asked by At

how i can preload mp3 background music file async in cocos2d? Like textures

        [[CCTextureCache sharedTextureCache] addImageAsync:@"textures.png" target:self selector:@selector(textureLoaded:)];     

i search only this solution

 SimpleAudioEngine *sae = [SimpleAudioEngine sharedEngine];
if (sae != nil) {
    [sae preloadBackgroundMusic:@"mula_tito_on_timbales.mp3"];
    if (sae.willPlayBackgroundMusic) {
        sae.backgroundMusicVolume = 0.5f;
    }
}
1

There are 1 answers

0
badgerr On

You can't preload background music asynchronously using SimpleAudioEngine functions. The solution you posted will still work, though, as the SimpleAudioEngine data persists between cocos2d scenes.

If you really want it to be asynchronous, you could do it in a separate thread, or an NSOperation. This thread on the cocos2d forums has a number of suggestions.