我正在尝试使用 JLayer 播放 mp3。该文件在我的罐子里,但我不知道如何让它播放。如何为我的应用程序提供与我的类在同一个包中的 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();
}