Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming music synchronously from a mp3 file via a nodejs server + socket.io

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?

like image 268
codeAnand Avatar asked Feb 10 '12 16:02

codeAnand


1 Answers

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.

like image 139
Frankie Avatar answered Nov 06 '22 11:11

Frankie