JAVA,通过URL播放mp3

时间:2011-03-17 20:19:01

标签: java url stream mp3

我想创建通过网址从互联网播放mp3音乐的播放器。 我试过这个,但它不起作用:

import java.net.URL;
import sun.audio.AudioData;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
import sun.audio.ContinuousAudioDataStream;


public class Player {

  public static void main(String[] argv) throws Exception {

        URL url = new URL("http://stream10.jamendo.com/stream/247/mp31/07%20-%20Both%20-%20Je%20le%20veux%20aussi.mp3");
        AudioStream as = new AudioStream (url.openStream());
        AudioData data = as.getData();
        ContinuousAudioDataStream cas = new ContinuousAudioDataStream (data);
        AudioPlayer.player.start(cas);

  }

}

我收到了错误:

Exception in thread "main" java.io.IOException: could not create audio stream from input stream
        at sun.audio.AudioStream.<init>(AudioStream.java:65)
        at Player.main(Player.java:27)
Java Result: 1

我怎么能解决这个问题?

1 个答案:

答案 0 :(得分:0)

我相信,对于你选择的这个特定的库,太阳一个,不支持mp3,它归结为那个。正如@Treebranch所建议的那样,更好的方法是查看可能处理mp3的其他API。

从JavaZoom页面:

“MP3SPI是一个Java服务提供商接口,为Java平台增加了MP3(MPEG 1/2 / 2.5 Layer 1/2/3)音频格式支持”。