Tuesday, November 04, 2014

Android Lollipop Patch for Cocos2dxMusic.java (Cocos2d-x v2.2)

Patch for Cocos2dxMusic.java (Cocos2d-x v2.2)


  Index: Cocos2dxMusic.java
  ===================================================================
  --- Cocos2dxMusic.java (revision 21981)
  +++ Cocos2dxMusic.java (working copy)
  @@ -110,12 +110,12 @@
        Log.e(Cocos2dxMusic.TAG, "playBackgroundMusic: background media player is null");
      } else {
        // if the music is playing or paused, stop it
  - this.mBackgroundMediaPlayer.stop();
  + //this.mBackgroundMediaPlayer.pause();
   
        this.mBackgroundMediaPlayer.setLooping(isLoop);
   
        try {
  - this.mBackgroundMediaPlayer.prepare();
  + //this.mBackgroundMediaPlayer.prepare();
          this.mBackgroundMediaPlayer.seekTo(0);
          this.mBackgroundMediaPlayer.start();
   
  @@ -129,6 +129,9 @@
    public void stopBackgroundMusic() {
      if (this.mBackgroundMediaPlayer != null) {
        this.mBackgroundMediaPlayer.stop();
  + this.mBackgroundMediaPlayer.release();
  + this.mBackgroundMediaPlayer = null;
  + this.mCurrentPath = null;
   
        // should set the state, if not, the following sequence will be error
        // play -> pause -> stop -> resume
  @@ -152,10 +155,9 @@
   
    public void rewindBackgroundMusic() {
      if (this.mBackgroundMediaPlayer != null) {
  - this.mBackgroundMediaPlayer.stop();
   
        try {
  - this.mBackgroundMediaPlayer.prepare();
  + this.mBackgroundMediaPlayer.pause();
          this.mBackgroundMediaPlayer.seekTo(0);
          this.mBackgroundMediaPlayer.start();
 

No comments: