ajout d'une musique de fond

This commit is contained in:
Bastien NOEL 2020-04-24 14:14:46 +02:00
parent 3803becdcf
commit cd9de06a76
3 changed files with 41 additions and 1 deletions

View File

@ -12,7 +12,7 @@ public class Main extends Application{
@Override
public void start(Stage primaryStage) throws Exception{
System.out.println("Lancement de l'application");
Pane root = FXMLLoader.load(getClass().getResource("ressources/Jouer_tour(1)lancer_des.fxml"));
Pane root = FXMLLoader.load(getClass().getResource("ressources/Menu.fxml")); // "ressources/Jouer_tour(1)lancer_des.fxml"
primaryStage.setTitle("Shadow Hunters");
primaryStage.setScene(new Scene(root));
primaryStage.centerOnScreen();
@ -20,6 +20,11 @@ public class Main extends Application{
}
public static void main(String[] args) {
String filepath = "src//ihm//ressources//musique//The_Red_Fox_Tavern.wav"; //lien vers la musique : https://www.youtube.com/watch?v=LBpKUIyOHdo
Musique musiqueObjet = new Musique();
musiqueObjet.playMusique(filepath);
launch(args);
}
}

35
src/ihm/Musique.java Normal file
View File

@ -0,0 +1,35 @@
package ihm;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JOptionPane;
public class Musique {
public void playMusique(String path) {
try {
File musicPath = new File(path);
if( musicPath.exists()) {
AudioInputStream audioInput = AudioSystem.getAudioInputStream(musicPath);
Clip clip = AudioSystem.getClip();
clip.open(audioInput);
clip.start();
clip.loop(Clip.LOOP_CONTINUOUSLY);
} else {
System.out.println("le fichier audio n'est pas trouvé");
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

Binary file not shown.