My app throws 'java.io.IOException: could not create AudioData object'?
HI
I am trying to play an audio file in my Java application:
here is the code:
开发者_C百科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);
}
I have no idea what this exception means or if it is even finding the wav file im trying to play
java.io.IOException: could not create AudioData object
thanks
Thank got it working. Changed the code to:
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);
}
精彩评论