停止暂停并寻找音频流

时间:2014-04-09 13:59:08

标签: node.js audio

1)我正在使用节点扬声器和暂停流:

        var mp3Stream = fs.createReadStream(__dirname + '/sounds/' + filename);
        mp3Stream.pipe(new Lame.Decoder()).pipe(speaker);

        // ...
        function pause () { 
          if (isPlaying) {

              mp3Stream.pipe(pauseStream.pause());
              isPlaying = false;
          }
        }

并在暂停()触发几秒后暂停音频流。如何正确使用音频流来防止这种缓冲?

2)我按照这样切换曲目:

function play(params) { 

        if (isPlaying) {

            speaker.end();
            speaker = new Speaker({
                channels: 2,          // 2 channels
                bitDepth: 16,         // 16-bit samples
                sampleRate: 44100     // 44,100 Hz sample rate
            });
        }

        mp3Stream = fs.createReadStream(__dirname + '/sounds/' + params.filename);
        mp3Stream.pipe(new Lame.Decoder()).pipe(speaker);

        isPlaying = true;
}

可以吗?我担心我会得到内存泄漏

3)有没有简单的方法来寻找音频缓冲区?

谢谢!

0 个答案:

没有答案