0
我正在嘗試使用JLayer播放mp3。該文件在我的jar中,但我無法弄清楚如何使它發揮。我將如何給我的應用程序的MP3文件的路徑與我的類在相同的包? 這裏是我的代碼:使用JLayer播放mp3資源
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();
}