I am trying to use JLayer to play an mp3. The file is in my jar, but I can't figure out how to make it play. How would I give my app the path of the mp3 file in the same package as my classes? Here is my code:
File file = new File("audio.mp3");
System.out.println("located media at "+file.getAbsolutePath());
AdvancedPlayer player = null;
try {
player = new AdvancedPlayer(new FileInputStream(file),
FactoryRegistry.systemRegistry().createAudioDevice());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JavaLayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Starting the music... ");
try {
player.play();
} catch (JavaLayerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Why don't you try absolute path to play the song. Use this code for reference:
Note the use of double '\' in the path.