Skip to content
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

err.killed returns undefined #23

Open
Komoszek opened this issue Feb 10, 2018 · 4 comments
Open

err.killed returns undefined #23

Komoszek opened this issue Feb 10, 2018 · 4 comments

Comments

@Komoszek
Copy link

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).

@ZTiKnl
Copy link

ZTiKnl commented Jul 24, 2019

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');
  }
}

@ZTiKnl
Copy link

ZTiKnl commented Jul 24, 2019

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 ;)

@ZTiKnl
Copy link

ZTiKnl commented Jul 24, 2019

Although on second thought, perhaps err should be more than 1, so maybe not 'solved' just yet...

@hasanbasri1993
Copy link

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) { }); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants