class Sound
{
FileInputStream file;
BufferedInputStream buf;
public Sound()
{
try
{
file=new FileInputStream("./src/music/001.mid");
buf=new BufferedInputStream(file);
AudioStream audio=new AudioStream(buf);
AudioPlayer.player.start(audio);
}
catch (Exception e) {}
}
}
button下的是這個Sound play = new Sound();未打包前是可以正常播放的,打包後就不能了,mid文件有打包進去jar的
求大神解答,應該是用相對途徑吧,但就是不懂怎樣改
代碼結構圖
改成這個試試。
String musicPath = "001/flourish.mid";
InputStream input = this.getClass().getResourceAsStream(musicPath);
buf = new BufferedInputStream(input);