var Speaker = require('speaker'), fs = require('fs'), lame = require('lame');
playSong('closedoor.mp3'); //this function works only one time each runtime
function playSong(song) {
console.log("MUSIC START");
var readStream = fs.createReadStream('/home/pi/moteino/' + song);
$stream = readStream.pipe(new lame.Decoder())
.on('format', function (format) {
this.pipe(new Speaker(format));
});
$stream.on('close', function()
{
console.log("MUSIC DONE"); //"MUSIC DONE" never gets printed to the console.
});
}
I get a error message in my console: