New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop a streaming mp3 #52
Comments
try this: socket.on('playcontrol', function(data) {
if (data.action == 'play') {
console.log('playing');
speaker = new Speaker();
decoder = new lame.Decoder();
stream = request(data.songurl);
stream.pipe(decoder).pipe(speaker);
}
if (data.action == 'stop') {
if (stream) {
stream.unpipe();
}
console.log('stopping')
}
}) |
Thanks for the reply. I've tried your solution but its not working, actually doesn't make a difference. I've come up with the solution below which however is working erratically. if (stream){ This works like 60% of the time. The other times it gives me the following error: events.js:85 Am assuming the error comes up because the speaker is trying to write data that doesn't exist. Is there a way of flushing out data first before closing the speaker? Any suggestions on what I can try? |
This is working for me: stream = fs.createReadStream(file);
var decoder = new lame.Decoder();
var spkr = new Speaker();
decoder.pipe(spkr);
stream.pipe(decoder);
//Pause
setTimeout(function(){
//stream.unpipe(); - not sure if necessary
spkr.end();
}, 1000);
//Resume
setTimeout(function(){
decoder.pipe(new Speaker());
}, 5000); But there is a problem, It takes more than 1 second to stop playing, and I don't know if this is the correct way of handling this |
Other possible solution: // Lame decoder & speaker objects
var decoder = new lame.Decoder();
// pipe() returns destination stream
var spkr = decoder.pipe(new Speaker());
// manually write data to the decoder stream,
// which is a writeable stream
stream = fs.createReadStream(file);
stream.on('data', function (chunk) {
decoder.write(chunk);
});
setTimeout(function(){
decoder.unpipe();
}, 1000);
setTimeout(function(){
decoder.pipe(spkr);
}, 10000); |
Unfortunately I only receive exceptions when I try any of your solutions: unpipe(); TypeError: undefined is not a function I get this error when using the unpipe, the pause or the stop approach (is not a function - error). |
@RTK Can you post your code? |
I get my pcm data from ffmpeg, using fluent-ffmpeg: var stream = ;// ffmpeg pcm data stream.pipe(speaker); setTimeout(function() { maybe because i'm using windows 8.1 ? |
@RTK You are not piping the speaker, that's why you are getting an error. Try something like this: var stream = ;// ffmpeg pcm data
stream.pipe(new Speaker());
setTimeout(function() {
stream.unpipe();
}, 1000); |
Is there anyway of stopping output to a speaker? Am streaming a mp3 from an online music service. The mp3 comes as a signed url. Am using sockets.io and the app is set up on raspberry. I want users to be able to play and stop the mp3's. Playing isn't a problem but stopping is. Below is my code
socket.on('playcontrol', function(data){
if(data.action == 'play'){
I've tried various options like using throttle but no of them seem to work. Any idea what I can try?
The text was updated successfully, but these errors were encountered: