Friday 23 December 2016

Problems ending a piped stream

I'm doing a GET request to a shoutcast stream and streaming the data to my node.js program. I'm piping the response stream over to a an instance of node-lame's (http://ift.tt/OGQ50p) decoder, and then piping it to node-speaker (http://ift.tt/1cz8zEC) to finally make the shoutcast stream's audio play through my speakers, like so:res .pipe(decoder) .pipe(speaker); But I have a problem. I'd like to be able to stop/resume the stream on command, without exiting the program. So let's say, on hitting spacebar, the stream would get cut off. And then on hitting it again, it starts over again.The logic for handling user input is fine. What I have a problem with is actually ending the stream. I looked through the node documentation and right now I've got:res.unpipe(decoder); decoder.unpipe(speaker); res.end(); But no matter what I do, I always get a "Write after end" error. I want to kill off the stream entirely without the program ending. Is that possible?

Submitted December 23, 2016 at 10:56AM by foulbeast

No comments:

Post a Comment