nomadhoc/sound-play

Imprecise wait duration

Opened this issue · 0 comments

At the moment, it appears this libraries adds an extra 1-second wait before its promise resolves, in order to wait for the file/duration to load: (the Start-Sleep 1; part)

[...]
const stopAudio = `Start-Sleep 1; Start-Sleep -s $player.NaturalDuration.TimeSpan.TotalSeconds;Exit;`

const windowPlayCommand = (path, volume) =>
  `powershell -c ${addPresentationCore} ${createMediaPlayer} ${loadAudioFile(
    path,
  )} $player.Volume = ${volume}; ${playAudio} ${stopAudio}`

This is unfortunate as it means the caller does not know precisely when the audio ends, creating unwanted gaps between audio in some cases.

An improvement could be to just loop until the duration is discovered, as seen here: https://stackoverflow.com/a/18475408/2441655