23 lines
706 B
Java
23 lines
706 B
Java
|
package fr.monkhanny.dorfromantik.utils;
|
||
|
|
||
|
import javax.sound.sampled.*;
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
|
||
|
public class SoundLoader {
|
||
|
|
||
|
public static Clip loadMusic(String filePath) {
|
||
|
try {
|
||
|
File soundFile = new File(filePath);
|
||
|
AudioInputStream audioStream = AudioSystem.getAudioInputStream(soundFile);
|
||
|
Clip clip = AudioSystem.getClip();
|
||
|
clip.open(audioStream);
|
||
|
return clip;
|
||
|
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
|
||
|
e.printStackTrace();
|
||
|
System.err.println("Failed to load sound at path: " + filePath);
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|