I would like to create player that play mp3 music from the internet by url.

I tried this, but it doesn't work:

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);

}

}

I got error:

Exception in thread "main" java.io.IOException: could not create audio stream from input stream

at sun.audio.AudioStream.(AudioStream.java:65)

at Player.main(Player.java:27)

Java Result: 1

How could I solve this problem?

解决方案

I believe that for this specific library you have chosen, the Sun one, there is not support for mp3 and it comes down to exactly that. As @Treebranch suggests, the better approach is to look at other APIs which could possibly handle mp3s.

From the JavaZoom page:

"MP3SPI is a Java Service Provider Interface that adds MP3 (MPEG 1/2/2.5 Layer 1/2/3) audio format support for Java Platform".

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐