How to loop an MP3?
I use this to play an MP3, but it only plays once.
I want to play the MP3 continuously.
/*jslint node: true, vars: true, maxerr: 50, indent: 4 */
(function (console, require, alarm) {
"use strict";
var fs = require("fs");
var lame = require("lame");
var Speaker = require("speaker");
function start() {
var stream = fs.createReadStream("sounds/alarm.mp3");
stream.pipe(new lame.Decoder()).pipe(new Speaker());
}
alarm.start = start;
}(global.console, require, exports));
Using:
- node-lame: https://github.com/TooTallNate/node-lame
- node-speaker: https://github.com/TooTallNate/node-speaker
stream.on("close", function () { start(); });
, but that did not work. It started playing several MP3s simultaneously and then stopped. – Boundarystream.pipe(decoder, {end: false}).pipe(speaker, {end: false});
. This causes Node to eat all the memory and then crash: "FATAL ERROR: Evacuation Allocation failed - process out of memory". – Boundary