0

我正在尝试用 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
4

1 回答 1

0

you have to give the absolute path name. something like . c://music//yourfilename.wav

OR try this:

 audioS = new AudioStream(new FileInputStream("./TheDragonBornComes.wav"));
于 2012-10-29T20:39:31.730 回答