add SoundHandler to Play sounds and Mute global
This commit is contained in:
parent
b8a450c7dc
commit
07b839fef5
|
@ -0,0 +1,9 @@
|
|||
<component name="libraryTable">
|
||||
<library name="jlayer-1.0.3">
|
||||
<CLASSES>
|
||||
<root url="jar://$USER_HOME$/Downloads/jlayer-master/jlayer-master/target/jlayer-1.0.3.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</component>
|
|
@ -7,5 +7,6 @@
|
|||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="jlayer-1.0.3" level="project" />
|
||||
</component>
|
||||
</module>
|
|
@ -1,8 +1,19 @@
|
|||
public class HalloSchiffeVersenken {
|
||||
|
||||
public static void main(String[] args){
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
System.out.println("HelloSchiffeVersenekn");
|
||||
|
||||
|
||||
System.out.println("sound");
|
||||
SoundHandler.playSound("hit");
|
||||
Thread.sleep(3000);
|
||||
System.out.println("sound");
|
||||
SoundHandler.playSound("hit");
|
||||
SoundHandler.setSoundOn(false);
|
||||
System.out.println("sound off");
|
||||
SoundHandler.playSound("hit");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
import javazoom.jl.decoder.JavaLayerException;
|
||||
import javazoom.jl.player.Player;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SoundHandler {
|
||||
|
||||
private static boolean soundOn = true;
|
||||
private static HashMap<String, String> sounds = new HashMap<String, String>(Map.of(
|
||||
"hit", "~/../../Sound/water-drip.mp3"
|
||||
));
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void add(String soundName, String path){
|
||||
sounds.put(soundName, path);
|
||||
}
|
||||
|
||||
static void setSoundOn(boolean sound){
|
||||
soundOn= sound;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
public class Sounds {
|
||||
private String soundName;
|
||||
private String path;
|
||||
|
||||
public Sounds(String soundName, String path){
|
||||
setSoundName(soundName);
|
||||
setPath(path);
|
||||
}
|
||||
|
||||
public String getSoundName() {
|
||||
return soundName;
|
||||
}
|
||||
|
||||
public void setSoundName(String soundName) {
|
||||
this.soundName = soundName;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue