play-sound
play-sound copied to clipboard
err.killed returns undefined
Since version 1.1.2 version you can't check if process was killed because err.killed always returns undefined (err is only a number, not an object).
confirmed, same problem here
example code:
const sfx = require('play-sound')(opts = {player: "aplay"})
var voiceoutput;
voiceoutput = sfx.play('./output.wav', function(err){
if (err) {
console.log('Couldn\'t play: already playing');
if (err.killed) {
console.log('Stopped talking');
}
}
voiceoutput = null;
return
})
function silence() {
if (voiceoutput != null) {
voiceoutput.kill();
} else {
console.log('audio output already stopped');
}
}
This item can be marked 'solved', all that is required is an update to the example/readme file.
replace:
var audio = player.play('foo.mp3', function(err){
if (err && !err.killed) throw err
})
audio.kill()
with:
var audio = player.play('foo.mp3', function(err){
if (err && !audio.killed) throw err
})
audio.kill()
// audio.killed == true
in my example above, the code would change to:
if (voiceoutput.killed) {
console.log('Stopped talking');
}
@Komoszek tagging you in case you still need this on an old project ;)
Although on second thought, perhaps err should be more than 1, so maybe not 'solved' just yet...
not working .. with kill() hhm
so i use https://www.npmjs.com/package/tree-kill
audio = player.play('../media/jaros.mp3', false, function (err) { if (err && !audio.killed) throw err; });
pids.push(audio.pid);
for (let i = 0; i < pids.length; i++) { kill(pids[i], 'SIGKILL', function (err) { }); }