M431-ShadowHunterGame/src/ihm/EffetSonore.java

61 lines
1.2 KiB
Java
Raw Normal View History

2020-04-30 17:11:50 +02:00
package ihm;
2020-05-04 16:15:01 +02:00
import java.io.BufferedInputStream;
import java.io.InputStream;
2020-04-30 17:11:50 +02:00
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
public class EffetSonore {
2020-05-04 15:04:24 +02:00
static boolean soundOK;
2020-05-04 16:15:01 +02:00
public InputStream fileSound1 = getClass().getResourceAsStream("/ihm/ressources/musique/BEEP1.wav");
public InputStream fileSound2 = getClass().getResourceAsStream("/ihm/ressources/musique/BeepError.wav");
2020-04-30 17:11:50 +02:00
2020-05-04 16:15:01 +02:00
public static void playSoundEffect(InputStream path) {
2020-04-30 17:11:50 +02:00
2020-05-04 15:04:24 +02:00
if (soundOK == true) {
2020-04-30 17:11:50 +02:00
try {
2020-05-04 16:15:01 +02:00
InputStream soundPath = path;
2020-04-30 17:11:50 +02:00
2020-05-04 16:15:01 +02:00
if (soundPath!=null) {
2020-04-30 17:11:50 +02:00
2020-05-04 16:15:01 +02:00
InputStream bufferedIn = new BufferedInputStream(soundPath);
AudioInputStream audioInput = AudioSystem.getAudioInputStream(bufferedIn);
2020-04-30 17:11:50 +02:00
Clip clipSound = AudioSystem.getClip();
clipSound.open(audioInput);
clipSound.start();
} else {
System.out.println("le fichier audio n'est pas trouvé");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
2020-05-04 15:04:24 +02:00
public static boolean isSoundOK() {
2020-04-30 17:11:50 +02:00
return soundOK;
}
2020-05-04 15:04:24 +02:00
public static void setSoundOK(boolean soundOK) {
EffetSonore.soundOK = soundOK;
2020-04-30 17:11:50 +02:00
}
2020-05-04 15:04:24 +02:00
2020-04-30 17:11:50 +02:00
}