add Sound in to Thread
This commit is contained in:
parent
810ffe7c5f
commit
521f6a578f
|
@ -7,9 +7,9 @@ public class HalloSchiffeVersenken {
|
|||
|
||||
System.out.println("sound");
|
||||
SoundHandler.playSound("hit");
|
||||
Thread.sleep(3000);
|
||||
System.out.println("sound");
|
||||
SoundHandler.playSound("hit");
|
||||
|
||||
Thread.sleep(10000);
|
||||
|
||||
SoundHandler.setSoundOn(false);
|
||||
System.out.println("sound off");
|
||||
SoundHandler.playSound("hit");
|
||||
|
|
|
@ -16,16 +16,22 @@ public class SoundHandler {
|
|||
|
||||
public static void playSound(String soundName) {
|
||||
if (soundOn) {
|
||||
try {
|
||||
Player player = new Player(new FileInputStream(sounds.get(soundName)));
|
||||
player.play();
|
||||
} catch (JavaLayerException | FileNotFoundException e) {
|
||||
System.out.println("dslkfsfnsldfnlsnfsdnölscls");
|
||||
e.printStackTrace();
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Player player = new Player(new FileInputStream(sounds.get(soundName)));
|
||||
player.play();
|
||||
} catch (JavaLayerException | FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void add(String soundName, String path){
|
||||
sounds.put(soundName, path);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue