Skip to content

Commit

Permalink
fixed cocos2d#885: make SimpleAudioEngine::setEffectVolume() take eff…
Browse files Browse the repository at this point in the history
…ect immediately on android
  • Loading branch information
minggo committed Dec 1, 2011
1 parent 9537cf8 commit 5c33014
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
16 changes: 16 additions & 0 deletions HelloLua/android/src/org/cocos2dx/lib/Cocos2dxSound.java
Expand Up @@ -187,8 +187,24 @@ public float getEffectsVolume(){
return (this.mLeftVolume + this.mRightVolume) / 2;
}

@SuppressWarnings("unchecked")
public void setEffectsVolume(float volume){
// volume should be in [0, 1.0]
if (volume < 0){
volume = 0;
}
if (volume > 1){
volume = 1;
}

this.mLeftVolume = this.mRightVolume = volume;

// change the volume of playing sounds
Iterator<?> iter = this.mSoundIdStreamIdMap.entrySet().iterator();
while (iter.hasNext()){
Map.Entry<Integer, Integer> entry = (Map.Entry<Integer, Integer>)iter.next();
this.mSoundPool.setVolume(entry.getValue(), mLeftVolume, mRightVolume);
}
}

public void end(){
Expand Down
16 changes: 16 additions & 0 deletions HelloWorld/android/src/org/cocos2dx/lib/Cocos2dxSound.java
Expand Up @@ -187,8 +187,24 @@ public float getEffectsVolume(){
return (this.mLeftVolume + this.mRightVolume) / 2;
}

@SuppressWarnings("unchecked")
public void setEffectsVolume(float volume){
// volume should be in [0, 1.0]
if (volume < 0){
volume = 0;
}
if (volume > 1){
volume = 1;
}

this.mLeftVolume = this.mRightVolume = volume;

// change the volume of playing sounds
Iterator<?> iter = this.mSoundIdStreamIdMap.entrySet().iterator();
while (iter.hasNext()){
Map.Entry<Integer, Integer> entry = (Map.Entry<Integer, Integer>)iter.next();
this.mSoundPool.setVolume(entry.getValue(), mLeftVolume, mRightVolume);
}
}

public void end(){
Expand Down
16 changes: 16 additions & 0 deletions tests/test.android/src/org/cocos2dx/lib/Cocos2dxSound.java
Expand Up @@ -187,8 +187,24 @@ public float getEffectsVolume(){
return (this.mLeftVolume + this.mRightVolume) / 2;
}

@SuppressWarnings("unchecked")
public void setEffectsVolume(float volume){
// volume should be in [0, 1.0]
if (volume < 0){
volume = 0;
}
if (volume > 1){
volume = 1;
}

this.mLeftVolume = this.mRightVolume = volume;

// change the volume of playing sounds
Iterator<?> iter = this.mSoundIdStreamIdMap.entrySet().iterator();
while (iter.hasNext()){
Map.Entry<Integer, Integer> entry = (Map.Entry<Integer, Integer>)iter.next();
this.mSoundPool.setVolume(entry.getValue(), mLeftVolume, mRightVolume);
}
}

public void end(){
Expand Down

0 comments on commit 5c33014

Please sign in to comment.