2020-04-30 17:11:50 +02:00
|
|
|
package ihm;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
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-04-30 17:11:50 +02:00
|
|
|
|
2020-05-04 15:04:24 +02:00
|
|
|
public static void playSoundEffect(String 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 {
|
|
|
|
|
|
|
|
File soundPath = new File(path);
|
|
|
|
|
|
|
|
if (soundPath.exists()) {
|
|
|
|
|
|
|
|
AudioInputStream audioInput = AudioSystem.getAudioInputStream(soundPath);
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|