Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  stream music with java  (Read 4446 times)
0 Members and 1 Guest are viewing this topic.
Offline pudelhund

Junior Newbie





« Posted 2012-03-22 08:44:07 »

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!
Offline jimeowan

Junior Member


Medals: 1
Projects: 1



« Reply #1 - Posted 2012-03-22 11:04:27 »

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

Author of "The Little Scientist" (judging panel winner for Java4K 2012 </brag>)
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2012-03-23 04:01:36 »

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.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (16 views)
2014-07-24 01:59:36

Riven (16 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (16 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!