play-sound icon indicating copy to clipboard operation
play-sound copied to clipboard

pause/resume functions

Open alexey-sh opened this issue 7 years ago • 4 comments

Is there any way to pause/resume audio? Thanks

alexey-sh avatar May 01 '17 13:05 alexey-sh

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

MalikMahnoor avatar Jun 21 '17 04:06 MalikMahnoor

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

fsegouin avatar May 03 '18 11:05 fsegouin

Yeah that is definetely needed

talentlessguy avatar Nov 11 '19 19:11 talentlessguy

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

MARCoTheRobot avatar Mar 28 '23 14:03 MARCoTheRobot