Skip to content

Commit

Permalink
Update webaudio.ts stopAT
Browse files Browse the repository at this point in the history
Add function for precise playback
  • Loading branch information
xinyuaixiaoyu authored Nov 8, 2023
1 parent 1280065 commit 1f05c2b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/webaudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ class WebAudioPlayer extends EventEmitter<WebAudioPlayerEvents> {
this.emit('pause')
}

stopAt(timeSeconds) {
const delay = timeSeconds - this.currentTime
this.bufferNode?.stop(this.audioContext.currentTime + delay)

this.bufferNode?.addEventListener('ended', () => {
this.bufferNode = null
this.pause()
}, { once: true })
}

async setSinkId(deviceId: string) {
const ac = this.audioContext as AudioContext & { setSinkId: (id: string) => Promise<void> }
return ac.setSinkId(deviceId)
Expand Down

0 comments on commit 1f05c2b

Please sign in to comment.