用Java流音乐 [英] stream music with java

查看:101
本文介绍了用Java流音乐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一些聊天程序,现在想通过客户端命令播放音乐,例如:

I am currently coding some chat program and now want to play music via a client command like:

/music http://somewebsite.com/somesong.mp3

因此,链接将从发送歌曲的客户端发送到服务器.然后,服务器应下载歌曲,并将其流式传输到每个客户端(他们也不应下载).问题是,我不知道如何通过基于TCP的连接流式传输mp3.

So the link would be sent from the client that sent the song, to the server. The server should then without downloading the song, stream it to every client (they shouldn't download it as well). Problem is, I don't know how to stream mp3's over a TCP based connection.

我的问题是,是否有人可以向我提供我所需要的库/教程/想法/代码示例.

My question is, if someone could provide me with libraries/tutorials/ideas/code examples of what I need.

作为一种选择,也可以直接从一个客户端的计算机流式传输音乐.如果我(作为客户)在计算机上播放歌曲(使用VLC等类似的音乐播放器),然后键入某个命令(例如/stream ),则来自声卡的声音将被流式传输到服务器,然后再到每个登录的客户端.

As an alternative directly streaming music from one client's computer would be okay as well. If I (as a client) play a song on my machine (using some music player like VLC or similar) and then type a certain command (maybe /stream), the sounds from my soundcard would be streamed to the server and then to every client logged in.

如果您能同时给我和我提供一些建议,那真是太棒了,Google到目前为止还没有真正的帮助,主要是因为我不太了解我应该搜索什么.

It would be awesome if you could provide me with some advice for both, Google didn't really help so far, mainly because I don't quite understand what I should search for.

提前谢谢!

推荐答案

我发现了一个库,它确实可以完成我想做的事情: http://www.javazoom.net/javalayer/javalayer.html

I found a library that does exactly what I want to do: http://www.javazoom.net/javalayer/javalayer.html

public void play() {
        String song = "http://www.ntonyx.com/mp3files/Morning_Flower.mp3";
        Player mp3player = null;
        BufferedInputStream in = null;
        try {
          in = new BufferedInputStream(new URL(song).openStream());
          mp3player = new Player(in);
          mp3player.play();
        } catch (MalformedURLException ex) {
        } catch (IOException e) {
        } catch (JavaLayerException e) {
        } catch (NullPointerException ex) {
        }

}

希望可以帮助所有人解决类似问题的希望:-)

Hope that helps everyone with a similar question :-)

这篇关于用Java流音乐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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