3

Hi i am new in cocos2d android. I couldn't find SimpleAudioEngine and CDAudioEngine in android cocos2d that is in iphone cocos2d. Then how can i play background music in android.

Guru
  • 21,652
  • 10
  • 63
  • 102
ArunGJ
  • 2,685
  • 21
  • 27

3 Answers3

3

hi here the code which i use try this is the way where you can use sound engine in four override methods hope it will help full for u

 @Override
 protected void onStart() {
// Preload background music
SoundEngine.sharedEngine().preloadSound(context, R.raw.theme_ver1);
SoundEngine.sharedEngine().playSound(context, R.raw.theme_ver1, true);
            SoundEngine.sharedEngine().preloadEffect(CCDirector.sharedDirector().getActivity(), R.raw.object_tap2);
            super.onStart();
        }

@Override
    protected void onPause() {
        SoundEngine.sharedEngine().pauseSound();
        super.onPause();
    }

    @Override
    protected void onResume() {     
        SoundEngine.sharedEngine().resumeSound();
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        SoundEngine.sharedEngine().realesAllEffects();
        SoundEngine.sharedEngine().realesAllSounds();
        SoundEngine.purgeSharedEngine();
        super.onDestroy();
    } 
2

You have to use SoundEngine (org.cocos2d.sound.SoundEngine).

Put your music file in res/raw folder and add the following code

SoundEngine.sharedEngine().playSound(context, R.raw.your_music, true);
zov
  • 4,092
  • 1
  • 16
  • 19
0

I hope this will help you.

Context context = CCDirector.sharedDirector().getActivity();
    SoundEngine.sharedEngine().preloadEffect(context, R.raw.pew_pew_lei);
    SoundEngine.sharedEngine().playSound(context, R.raw.background_music_aac, true);

To stop the music

SoundEngine.sharedEngine().realesAllSounds();
Bebin T.N
  • 2,539
  • 1
  • 24
  • 28