【问题标题】:how to play background music in android cocos2d如何在android cocos2d中播放背景音乐
【发布时间】:2011-09-24 00:03:54
【问题描述】:

嗨,我是 cocos2d android 的新手。我在 iphone cocos2d 中的 android cocos2d 中找不到 SimpleAudioEngine 和 CDAudioEngine。那么如何在android中播放背景音乐。

【问题讨论】:

    标签: android cocos2d-android simpleaudioengine


    【解决方案1】:

    你好,我使用的代码试试这是你可以在四种覆盖方法中使用声音引擎的方式,希望它对你有帮助

     @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】:

      你必须使用 SoundEngine (org.cocos2d.sound.SoundEngine)。

      将你的音乐文件放入 res/raw 文件夹并添加以下代码

      SoundEngine.sharedEngine().playSound(context, R.raw.your_music, true);
      

      【讨论】:

        【解决方案3】:

        希望对您有所帮助。

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

        停止音乐

        SoundEngine.sharedEngine().realesAllSounds();
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-11-23
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多