想在java项目里添加音乐播放mp3
用的player方法做的,通过file方法读取路径,本地没问题读取项目中的WebContent/music/cc.mp3就不行
@RequestMapping("cc2")
public String toaccb()throws FileNotFoundException, JavaLayerException{
File file = new File("/music/cc.mp3");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream stream = new BufferedInputStream(fis);
Player player = new Player(stream);
player.play();
return "cc2";
}
public void play() {
new Thread(new Runnable() {
@Override
public void run() {
try {
File file = new File("/music/cc.mp3");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream stream = new BufferedInputStream(fis);
player = new Player(stream);
player.play();
} catch (Exception e) {
// TODO: handle exception
}
}
}).start();
try {
Thread.sleep(200000);
} catch (InterruptedException e) {
e.printStackTrace();
}
player.close();
}
运行结果报错找不到路径
我查询了很多file都是读取的本机路径 ,也试了在服务器读取/usr/local路径也不行
我主要是想要把项目放在服务器上面,能播放音乐