13

I have a mp3 file on my server.

And i want all my clients who visit that url to listen to that music in sync.

That is.

Lets say the file plays for 6 minutes.

I start the song at 10:00am

A request which comes at 10:03am should start listening from the 3rd minute of the song.

All my clients should listen to the song in sync.

How can I achieve this with nodejs and socket.io?

Cœur
  • 37,241
  • 25
  • 195
  • 267
codeAnand
  • 990
  • 1
  • 8
  • 29

1 Answers1

7

EDIT: If you want to do exactly what was asked the answer on the link is a much better match:

https://stackoverflow.com/a/26029102/67945

My original answer looses itself on the benefits of ipv4 multicasting.


What you are looking for is streaming.

The benefits added to the usage of streaming (opposed to every client having it's own open connection) are specially visible as your listeners base grow but the feed remains using the same bandwidth. Else you would grow into bandwidth problems pretty fast.

Streaming is a protocol (as http) and you can check a list of Streaming Servers here.

A very popular (and free) streaming server is IceCast.
And with a little Flash you can have a client player.

Community
  • 1
  • 1
Frankie
  • 24,627
  • 10
  • 79
  • 121
  • @SAnandNarayan I'm not really sure as they have a restrict by IP policy and, as I'm outside the US I can't access their website. But most radios work this way, yes. – Frankie Feb 10 '12 at 17:34
  • from what i hear, are you saying that this not possible over http? – codeAnand Feb 10 '12 at 17:36
  • @SAnandNarayan it sure is possible, people just tend to use the proper tool for the job and what you describe in your question fits perfectly in the definition of streaming media. – Frankie Feb 10 '12 at 17:37
  • 1
    thanks a tonne frankie, i need to research this... Thanks for you time... i will ping you when i get stuck somewhere thank you :-) – codeAnand Feb 10 '12 at 17:40
  • @SAnandNarayan you're welcome! Good luck on your endeavor! :) You'll thank yourself latter on you went the way of the streaming server. – Frankie Feb 10 '12 at 17:44
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7541/discussion-between-sanandnarayan-and-frankie) – codeAnand Feb 10 '12 at 17:59
  • IPv4 multicast is only inside LAN networks... i dont think icecast would save the bandwidth – codeAnand Feb 29 '12 at 22:55
  • *The benefits added to the usage of streaming (opposed to every client having it's own open connection) are specially visible as your listeners base grow but the feed remains using the same bandwidth.* I don't think that this statement is correct. When a client connect to your server he will consume from your stream and take a part from the bandwidth.. what you're talking about is correct ONLY when using a FM/AM physical radio, please edit your answer to add this detail.. – Marwen Trabelsi Dec 30 '16 at 00:43
  • 1
    @MarwenTrabelsi as stated by codeAnand I was actually referring to multicasting and, while the great majority of ISP's block it you can still implement it using tunnels. I will clarify the response. – Frankie Jan 04 '17 at 01:20