stream music with java

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

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

So the link would be send 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.

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.

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.

Thanks in advance!

The thing is there’s no way you can broadcast music without downloading it. You can broadcast music while downloading it though, and that’s what streaming is :stuck_out_tongue:

Now after some quick Googling I found a few leads for how to do it. For instance:
http://stackoverflow.com/questions/6159138/streaming-music-files-in-java points to two existing projects for hosting audio broadcasting servers.
Another common solution would be to use an independent broadcasting server (like IceCast) and make your server send data to it/control it.

One thing that you should consider though is: are you sure you want to use the server to broadcast sound? An alternative would be to simply broadcast the command, and let clients process it themselves.
On one hand using a server for the streaming is probably more flexible, as you can then easily add other sound-related commands without having to modify the clients, but on the other hand it might induce an important traffic.

Well using an InputStream isn’t that hard, just open a connection on the URL object and then feed the data to something that can translate MP3 to raw audio. If you want to use Java Sound, you’ll have to Google around for a Java Sound MP3 SPI.