0

Just wondering how to use my .wav in my jar using the library slick. 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);
    }   
}
Paul Dolega
  • 2,446
  • 14
  • 23
  • Possible duplicate of [load file within a jar](http://stackoverflow.com/questions/4548699/load-file-within-a-jar) – shmosel Dec 13 '16 at 04:59

1 Answers1

0

To play music use class MediaPlayer. Constructor MediaPlayer(Media media); constructor Media(String source);

new MediaPlayer(new Media("source"));

This object can play(), pause()...See documentation.

Ok try this:

new Media(YourClass.class.getResource("audio.mp3").toURI().toString());

This works fine for me.

Grzesiek
  • 11
  • 2
  • What would I use as the source if I wanted to use the audio from the packaged resource. For instance for an icon loader DisplayIcon.class.getResource("DisplayIcon.png") – BobbyJuniorPlays Dec 14 '16 at 02:40