Skip to content

Instantly share code, notes, and snippets.

@j0n
Created November 5, 2013 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j0n/7325170 to your computer and use it in GitHub Desktop.
Save j0n/7325170 to your computer and use it in GitHub Desktop.
Quick example of stream the same sound at the same timemark (bad bad sync) to different devices
var Throttle = require('throttle'),
fs = require('fs'),
change = false,
probe = require('node-ffprobe'),
http = require('http'),
bitRate = 128022;
currentStream = false;
probe(__dirname + '/my.mp3', function(err, data) {
bitRate = data.format.bit_rate;
currentStream = fs.createReadStream(__dirname + '/sounds/two.mp3');
})
var server = http.createServer(function(req, res){
if (req.url === '/') {
if (!currentStream) {
res.send('oops not ready, reload in 0.1 sec');
}
else {
res.write('<!doctype html> <html> <head> <title>Play</title> </head> <body> <h1>Play 4</h1> <audio autoplay controls id="yo" src="/bas"></audio> </body> </html>');
res.end();
}
}
else {
var t = new Throttle({ bps: (bitRate/10) * 1.4 });
currentStream.pipe(t).on('data', function(data){ res.write(data); });
}
});
server.listen(9888);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment