shime / play-sound

Play sounds by shelling out to one of the available audio players.
MIT License
207 stars 31 forks source link

pause/resume functions #18

Open alexey-sh opened 7 years ago

alexey-sh commented 7 years ago

Is there any way to pause/resume audio? Thanks

MalikMahnoor commented 7 years ago

I also have the same issue .I want to make sure that audio gets completed before I resume my further work

fsegouin commented 6 years ago

Any news on this? Would be a neat feature :)

talentlessguy commented 4 years ago

Yeah that is definetely needed

MARCoTheRobot commented 1 year ago

For anyone who might encounter this problem in the future, the workaround I found was by passing the 'SIGSTOP' and 'SIGCONT' flags when killing the audio process to pause and resume as mentioned in this SO post:

https://stackoverflow.com/questions/45319145/how-to-pause-process-in-node-js-using-spawn#:~:text=Simpler%2C%20you%20can%20call%20process,SIGCONT')%20to%20resume%20it

My code ended up looking something like this:

// access the node child_process as mentioned in the README
var audio = player.play('foo.mp3', function(err){
  if (err && !err.killed) throw err
})

//To pause
audio.kill('SIGSTOP');

//To resume
audio.kill('SIGCONT');

I have only tested this on a Mac with afplayer as the default player, and I plan on testing it on the Linux board I'll be moving this over, so I can't speak to how well this works with other player or on Windows or Linux (yet).