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);
嗯,路径不对了。
http://www.cnblogs.com/leehongee/p/3324062.html
http://bbs.csdn.net/topics/340003126
看看你是web项目还是app项目吧
贴一下你的代码结构图?或者自己在file下面输出下file的路径调试下。
2022年前来考古,我也遇到相同问题,不过我添加bgm的方法是创建一个intentserver