Implemented level 9
Concurrency-bug-fixes in soundManager
This commit is contained in:
@ -19,7 +19,7 @@ public class Bomb extends Tool {
|
||||
private Vector offsetToObstaclePosition = new Vector();
|
||||
|
||||
public Bomb(Vector position) {
|
||||
super(ToolType.BOMB, position, .2f, .2f, false, false);
|
||||
super(ToolType.BOMB, position, .25f, .25f, false, false);
|
||||
animation.setIndexSequence(new int[]{0, 1, 2});
|
||||
animation.setLooping(false);
|
||||
animation.setRequiredDelta(
|
||||
|
@ -6,6 +6,7 @@ import android.media.SoundPool;
|
||||
import android.support.annotation.RawRes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@ -41,7 +42,7 @@ public class SoundManager {
|
||||
public final Sound placeToolSound;
|
||||
public final Sound magnetSound;
|
||||
|
||||
private List<SoundStream> allStartedStreams = new ArrayList<>();
|
||||
private final List<SoundStream> allStartedStreams = Collections.synchronizedList(new ArrayList<SoundStream>());
|
||||
|
||||
public SoundManager(GameActivity gameActivity) {
|
||||
this.context = gameActivity;
|
||||
@ -86,10 +87,12 @@ public class SoundManager {
|
||||
|
||||
public void setSoundsMuted(boolean soundsMuted) {
|
||||
this.soundsMuted = soundsMuted;
|
||||
for (SoundStream stream : allStartedStreams) {
|
||||
float systemVolume = getSystemVolume();
|
||||
soundPool.setVolume(stream.getId(), systemVolume * stream.getModifiedVolume(),
|
||||
systemVolume * stream.getModifiedVolume());
|
||||
synchronized (allStartedStreams) {
|
||||
for (SoundStream stream : allStartedStreams) {
|
||||
float systemVolume = getSystemVolume();
|
||||
soundPool.setVolume(stream.getId(), systemVolume * stream.getModifiedVolume(),
|
||||
systemVolume * stream.getModifiedVolume());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,13 +126,17 @@ public class SoundManager {
|
||||
}
|
||||
|
||||
public void pauseAllSounds() {
|
||||
for (SoundStream stream : allStartedStreams)
|
||||
soundPool.pause(stream.getId());
|
||||
synchronized (allStartedStreams) {
|
||||
for (SoundStream stream : allStartedStreams)
|
||||
soundPool.pause(stream.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void resumeAllSounds() {
|
||||
for (SoundStream stream : allStartedStreams)
|
||||
soundPool.resume(stream.getId());
|
||||
synchronized (allStartedStreams) {
|
||||
for (SoundStream stream : allStartedStreams)
|
||||
soundPool.resume(stream.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
@ -169,8 +176,10 @@ public class SoundManager {
|
||||
}
|
||||
|
||||
public void stopAllSounds() {
|
||||
for (SoundStream stream : allStartedStreams)
|
||||
soundPool.stop(stream.getId());
|
||||
synchronized (allStartedStreams) {
|
||||
for (SoundStream stream : allStartedStreams)
|
||||
soundPool.stop(stream.getId());
|
||||
}
|
||||
allStartedStreams.clear();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user