JAVA,通过URL播放mp3 [英] JAVA, play mp3 by URL

查看:611
本文介绍了JAVA,通过URL播放mp3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个播放器,该播放器通过url播放Internet上的mp3音乐. 我试过了,但是没用:

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

  }

}

我遇到了错误:

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

我该如何解决这个问题?

How could I solve this problem?

推荐答案

我相信,对于您选择的这个特定的库,Sun来说,不支持mp3,确切地说就是这样.正如@Treebranch所建议的那样,更好的方法是查看其他可能处理mp3的API.

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.

在JavaZoom页面上:

From the JavaZoom page:

"MP3SPI是Java服务提供者接口,它为Java平台添加了MP3(MPEG 1/2/2.5 Layer 1/2/3)音频格式支持."

"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".

这篇关于JAVA,通过URL播放mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆