shime / play-sound

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

Export promisified play function #32

Closed gakada closed 3 years ago

gakada commented 5 years ago

To allow functional/promisified interface like

const { play } = require('play-sound')

// await in async function, throw err, no access to process
await play('foo.mp3')

// or with a callback
const process = play('foo.mp3', err => {
  // ...
})

which will create a new player object in each play call. Promise is returned iff callback is not provided, otherwise process is returned.

With https://github.com/shime/play-sound/pull/31:

const { play } = require('play-sound')

// throw err which may have code/signal/killed
const { code, signal, killed } = await play('foo.mp3')

const process = play('foo.mp3', (err, { code, signal, killed }) => {
  // err also may have code/signal/killed
})