Merge pull request #509 from minggo/iss719

fixed #719: update java code to HelloLua & tests
This commit is contained in:
minggo 2011-09-15 01:24:51 -07:00
commit 55ab2aa708
4 changed files with 42 additions and 3 deletions

View File

@ -24,8 +24,7 @@ THE SOFTWARE.
package org.cocos2dx.lib;
import org.cocos2dx.hellolua.R;
import org.cocos2dx.application.R;
import android.app.Activity;
import android.app.AlertDialog;
@ -105,6 +104,10 @@ public class Cocos2dxActivity extends Activity{
accelerometer.disable();
}
public static void preloadBackgroundMusic(String path){
backgroundMusicPlayer.preloadBackgroundMusic(path);
}
public static void playBackgroundMusic(String path, boolean isLoop){
backgroundMusicPlayer.playBackgroundMusic(path, isLoop);
}

View File

@ -48,6 +48,22 @@ public class Cocos2dxMusic {
initData();
}
public void preloadBackgroundMusic(String path){
if ((mCurrentPath == null) || (! mCurrentPath.equals(path))){
// preload new background music
// release old resource and create a new one
if (mBackgroundMediaPlayer != null){
mBackgroundMediaPlayer.release();
}
mBackgroundMediaPlayer = createMediaplayerFromAssets(path);
// record the path
mCurrentPath = path;
}
}
public void playBackgroundMusic(String path, boolean isLoop){
if (mCurrentPath == null){
// it is the first time to play background music
@ -159,8 +175,8 @@ public class Cocos2dxMusic {
}
public void setBackgroundVolume(float volume){
if (this.mBackgroundMediaPlayer != null){
this.mLeftVolume = this.mRightVolume = volume;
if (this.mBackgroundMediaPlayer != null){
this.mBackgroundMediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume);
}
}

View File

@ -106,6 +106,10 @@ public class Cocos2dxActivity extends Activity{
accelerometer.disable();
}
public static void preloadBackgroundMusic(String path){
backgroundMusicPlayer.preloadBackgroundMusic(path);
}
public static void playBackgroundMusic(String path, boolean isLoop){
backgroundMusicPlayer.playBackgroundMusic(path, isLoop);
}

View File

@ -48,6 +48,22 @@ public class Cocos2dxMusic {
initData();
}
public void preloadBackgroundMusic(String path){
if ((mCurrentPath == null) || (! mCurrentPath.equals(path))){
// preload new background music
// release old resource and create a new one
if (mBackgroundMediaPlayer != null){
mBackgroundMediaPlayer.release();
}
mBackgroundMediaPlayer = createMediaplayerFromAssets(path);
// record the path
mCurrentPath = path;
}
}
public void playBackgroundMusic(String path, boolean isLoop){
if (mCurrentPath == null){
// it is the first time to play background music