Skip to content

Instantly share code, notes, and snippets.

@chaosprinz
Created October 22, 2015 18:53
Show Gist options
  • Save chaosprinz/e06a10dce1c39b5af287 to your computer and use it in GitHub Desktop.
Save chaosprinz/e06a10dce1c39b5af287 to your computer and use it in GitHub Desktop.
Here is a solution for controlling the mplayer using nodejs. Much cleaner and more efficient than my fifo-solution. Instead of process.stdin i could use a socket or an webservice or whatever, very simple.
var cp = require("child_process");
var fs = require("fs");
player = cp.spawn("mplayer",
["-slave","-idle","-quiet"]
);
player.stdout.on("data",function(data){
console.log("" + data);
});
player.stderr.on("data", function(data){
console.error("" + data);
});
process.stdin.setEncoding('utf8');
process.stdin.on('readable', function(){
var chunk = process.stdin.read();
if (chunk !== null){
player.stdin.write(chunk);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment