[英]How to play a WAV in Java, when the WAV is contained inside the JAR using a slick
Just wondering how to use my .wav in my jar using the library slick. 只是想知道如何使用库文件库在我的jar中使用.wav。 Currently here is my code and I don't want to change it to a different library.
目前,这里是我的代码,我不想将其更改为其他库。 Mostly because I've got lots of useful slick 'voids' inside it.
主要是因为我里面有很多有用的光滑“空洞”。 Here's the code so far...
到目前为止,这是代码...
public class AudioPlayer {
public static Map<String, Music> musicMap = new HashMap<String, Music>();
public static void load() throws SlickException{
musicMap.put("music", new Music(THIS IS WHERE THE STREAM/RESOURCES CODE WOULD GO));
}
public static Music getMusic(String key) {
return musicMap.get(key);
}
}
To play music use class MediaPlayer. 要播放音乐,请使用MediaPlayer类。 Constructor MediaPlayer(Media media);
构造函数MediaPlayer(Media media); constructor Media(String source);
构造函数Media(String source);
new MediaPlayer(new Media("source"));
This object can play(), pause()...See documentation. 该对象可以play(),pause()...请参阅文档。
Ok try this: 好的,试试这个:
new Media(YourClass.class.getResource("audio.mp3").toURI().toString());
This works fine for me. 这对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.