54 lines
1.6 KiB
Java
Raw Normal View History

2024-10-24 20:18:06 +02:00
package main;
2024-10-25 20:22:35 +02:00
2024-10-27 21:11:44 +01:00
import view.*;
2024-10-25 20:22:35 +02:00
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.*;
import java.net.URL;
2024-10-24 20:18:06 +02:00
2024-10-27 21:11:44 +01:00
/**
* Classe principale du programme qui initialise l'interface utilisateur
* et joue un fichier audio en boucle.
*/
2024-10-24 20:18:06 +02:00
public class Main {
2024-10-27 21:11:44 +01:00
/**
* Point d'entrée du programme. Initialise l'interface utilisateur
* et démarre la lecture en boucle de la musique de fond.
*
* @param args les arguments de ligne de commande (non utilisés)
*/
2024-10-24 20:18:06 +02:00
public static void main(String[] args) {
2024-10-25 20:22:35 +02:00
SwingUtilities.invokeLater(() -> {
MenuView menuView = new MenuView();
App.addView(menuView, App.MENU_VIEW);
App.showView(App.MENU_VIEW);
2024-10-27 21:11:44 +01:00
String filepath = "/java/Music/audio.wav";
PlayMusic(filepath);
2024-10-25 20:22:35 +02:00
});
}
2024-10-27 21:11:44 +01:00
/**
* Joue un fichier audio en boucle.
*
* @param location le chemin d'accès au fichier audio à jouer
*/
2024-10-27 16:58:15 +01:00
public static void PlayMusic(String location) {
2024-10-25 20:22:35 +02:00
try {
URL url = Main.class.getResource(location);
if (url != null) {
AudioInputStream audioInput = AudioSystem.getAudioInputStream(url);
Clip clip = AudioSystem.getClip();
clip.open(audioInput);
clip.start();
2024-10-27 21:11:44 +01:00
clip.loop(Clip.LOOP_CONTINUOUSLY); // Boucle en continu
2024-10-25 20:22:35 +02:00
} else {
2024-10-27 16:58:15 +01:00
System.out.println("Fichier audio introuvable");
2024-10-25 20:22:35 +02:00
}
} catch (Exception e) {
System.out.println(e);
}
2024-10-24 20:18:06 +02:00
}
}