HI
我正在尝试在我的Java应用程序中播放音频文件:
这是代码:
public static void music()
{
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null;
try
{
BGM = new AudioStream(new FileInputStream("\\BattleShip\\battle.wav"));
MD = BGM.getData();
loop = new ContinuousAudioDataStream(MD);
}
catch(FileNotFoundException e){
System.out.print(e.toString());
}
catch(IOException error)
{
System.out.print(error.toString());
}
MGP.start(loop);
}
我不知道这个异常意味着什么,或者它是否甚至找到了试图播放的wav文件
java.io.IOException: could not create AudioData object
感谢
答案 0 :(得分:1)
感谢它的运作。将代码更改为:
public static void music()
{
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinuousAudioDataStream loop = null;
try
{
InputStream test = new FileInputStream("./battle.wav");
BGM = new AudioStream(test);
AudioPlayer.player.start(BGM);
//MD = BGM.getData();
//loop = new ContinuousAudioDataStream(MD);
}
catch(FileNotFoundException e){
System.out.print(e.toString());
}
catch(IOException error)
{
System.out.print(error.toString());
}
MGP.start(loop);
}