I'm trying to spawn mplayer as a child process, sometimes with a file to play and other times with a stream to play. The file works fine, but when I create a stream from the file, I get this error:
events.js:85 throw er; // Unhandled 'error' event ^ Error: read ECONNRESET at exports._errnoException (util.js:746:11) at Pipe.onread (net.js:550:26)
It's not a file permissions problem because I ran it as sudo and still had the same issue.
To test a potential problem with streaming, I created a write stream from the read stream and that worked without a problem.
I'm not really sure what to do next. I'd appreciate any advice or help.
Here's the code:
var fs = require('fs');
var spawn = require('child_process').spawn;
var file = "/usr/local/apps/ha6/web/voice/ga.wav";
var file2 = "/usr/local/apps/ha6/web/voice/ga2.wav";
function filePlay() {
var mplayer = spawn("mplayer", ["-slave", file], {stdio: ['pipe', 'ignore', 'ignore']});
mplayer.on("exit", function () {
console.log("exit");
});
}
function streamPlay() {
var str = fs.createReadStream(file).on("error", function (error) {
console.log("Error creating read stream:" + error);
});
var mplayer = spawn("mplayer", ["-slave "], {stdio: ['pipe', 'ignore', 'ignore']}).on("error", function (error) {
console.log("Spawn error " + error);
});
str.pipe(mplayer.stdin);
}
function testPiping() {
var str = fs.createReadStream(file).on("error", function (error) {
console.log("Error creating read stream:" + error);
});
var str2 = fs.createWriteStream(file2).on("error", function(error) {
console.log("Error creating write stream:" + error);
});
str.pipe(str2);
console.log("Pipe a success!");
}
filePlay(); // works fine
testPiping(); // works fine
streamPlay(); // ECONNRESET error