用Java加载音乐

时间:2012-10-29 20:36:58

标签: java

我正在尝试用Java创建一个媒体播放器。我已经创建了GUI,现在我需要加载一首歌。 我使用了AudioPlayer,但它不起作用。这是代码:

AudioPlayer audioP = AudioPlayer.player;
AudioStream audioS;
AudioData audioD;
ContinuousAudioDataStream loop = null;
audioS = new AudioStream(new FileInputStream("file:TheDragonBornComes.wav"));
audioD = audioS.getData();
loop = new ContinuousAudioDataStream(audioD);
audioP.start(loop);

错误是:

Exception in thread "main" java.io.FileNotFoundException: file:TheDragonBornComes.wav
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at medalmedia.MedalMedia.main(MedalMedia.java:26)

编辑:我已经更改了文件的位置,最后一个错误已经解决了。但是,有一个新的:

Exception in thread "main" java.io.IOException: could not create AudioData object

1 个答案:

答案 0 :(得分:0)

你必须给出绝对路径名。就像是 。 c://music//yourfilename.wav

或试试这个:

 audioS = new AudioStream(new FileInputStream("./TheDragonBornComes.wav"));