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:
Wait for the Speaker
instance's "finish" event before starting up a new instance.
var speaker = new Speaker();
speaker.on('finish', start);
stream.pipe(new lame.Decoder()).pipe(speaker);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With