Merge pull request 'add Sound in to Thread' (#5) from ole into main
Reviewed-on: #5 Reviewed-by: lgc <main@lugico.de>
This commit is contained in:
commit
2e8d2f5465
Binary file not shown.
|
@ -0,0 +1,36 @@
|
||||||
|
MAIN_CLASS := HalloSchiffeVersenken
|
||||||
|
JAR_NAME := schiffeVersenken.jar
|
||||||
|
|
||||||
|
SRC_DIR := src
|
||||||
|
OUT_DIR := bin
|
||||||
|
LIB_DIR := libs
|
||||||
|
|
||||||
|
JC := javac
|
||||||
|
JCFLAGS := -d $(OUT_DIR)/ -cp "$(LIB_DIR)/*"
|
||||||
|
|
||||||
|
JR := java
|
||||||
|
|
||||||
|
SEPERATOR := :
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
SEPERATOR := ;
|
||||||
|
endif
|
||||||
|
|
||||||
|
.SUFFIXES: .java
|
||||||
|
.PHONY: classfiles clean
|
||||||
|
|
||||||
|
|
||||||
|
classfiles: $(SRC_DIR)/*
|
||||||
|
$(JC) $(JCFLAGS) $(SRC_DIR)/*
|
||||||
|
|
||||||
|
jar: classfiles
|
||||||
|
jar --create --file=$(OUT_DIR)/$(JAR_NAME) --main-class=$(MAIN_CLASS) -C $(OUT_DIR)/ .
|
||||||
|
|
||||||
|
test-jar: jar
|
||||||
|
# $(JR) -cp "$(OUT_DIR)/:$(LIB_DIR)/*" $(MAIN_CLASS)
|
||||||
|
$(JR) -jar $(OUT_DIR)/$(JAR_NAME)
|
||||||
|
|
||||||
|
test: classfiles
|
||||||
|
$(JR) -cp "$(OUT_DIR)$(SEPERATOR)$(LIB_DIR)/*" $(MAIN_CLASS)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm $(OUT_DIR)/*.class
|
|
@ -7,9 +7,9 @@ public class HalloSchiffeVersenken {
|
||||||
|
|
||||||
System.out.println("sound");
|
System.out.println("sound");
|
||||||
SoundHandler.playSound("hit");
|
SoundHandler.playSound("hit");
|
||||||
Thread.sleep(3000);
|
|
||||||
System.out.println("sound");
|
Thread.sleep(10000);
|
||||||
SoundHandler.playSound("hit");
|
|
||||||
SoundHandler.setSoundOn(false);
|
SoundHandler.setSoundOn(false);
|
||||||
System.out.println("sound off");
|
System.out.println("sound off");
|
||||||
SoundHandler.playSound("hit");
|
SoundHandler.playSound("hit");
|
||||||
|
|
|
@ -10,21 +10,29 @@ import java.util.Map;
|
||||||
public class SoundHandler {
|
public class SoundHandler {
|
||||||
|
|
||||||
private static boolean soundOn = true;
|
private static boolean soundOn = true;
|
||||||
|
|
||||||
|
// Wenn fehler beim erstellen von .jar mit sound hier gucken
|
||||||
private static HashMap<String, String> sounds = new HashMap<String, String>(Map.of(
|
private static HashMap<String, String> sounds = new HashMap<String, String>(Map.of(
|
||||||
"hit", "~/../Sound/water-drip.mp3"
|
"hit", "./Sound/water-drip.mp3"
|
||||||
));
|
));
|
||||||
|
|
||||||
public static void playSound(String soundName) {
|
public static void playSound(String soundName) {
|
||||||
if (soundOn) {
|
if (soundOn) {
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Player player = new Player(new FileInputStream(sounds.get(soundName)));
|
Player player = new Player(new FileInputStream(sounds.get(soundName)));
|
||||||
player.play();
|
player.play();
|
||||||
} catch (JavaLayerException | FileNotFoundException e) {
|
} catch (JavaLayerException | FileNotFoundException e) {
|
||||||
System.out.println("dslkfsfnsldfnlsnfsdnölscls");
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void add(String soundName, String path){
|
static void add(String soundName, String path){
|
||||||
sounds.put(soundName, path);
|
sounds.put(soundName, path);
|
||||||
|
|
Loading…
Reference in New Issue