6

如何循环播放 MP3?

我用它来播放 MP3,但它只播放一次。

我想连续播放 MP3。

/*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));

使用:

4

1 回答 1

2

Speaker在启动新实例之前等待实例的“完成”事件。

var speaker = new Speaker();
speaker.on('finish', start);
stream.pipe(new lame.Decoder()).pipe(speaker);
于 2013-05-24T23:29:16.817 回答