D
D
dailysse2017-08-31 02:08:53
Node.js
dailysse, 2017-08-31 02:08:53

How to pause a stream?

var fs = require('fs');
var lame = require('lame');
var Speaker = require('speaker');

fs.createReadStream(process.argv[2])
  .pipe(new lame.Decoder())
  .on('format', function (format) {
    this.pipe(new Speaker(format));
  });

Good day to all. With this code, you can easily play an mp3 file in node.js. I also stuck rewind, volume, pauses and everything else here. But there is one question. How to make an instant pause playback? (well, maybe not instantaneous, but no more than with a delay of 100ms). Because if you just pause the stream, then the Speaker buffer will not stop until it has completely finished playing. I had an implementation with a reference to time, with the calculation of the flow time, but this is all somehow very sloppy and does not always work correctly. Maybe someone knows how to make an instant pause, without an audible (visible) delay? Thank you all in advance

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question