Skip to content

Commit

Permalink
Feat: add stopAT in WebAudioPlayer (#3325)
Browse files Browse the repository at this point in the history
* Update webaudio.ts stopAT

Add function for precise playback

* Update webaudio.ts

add timeSeconds type
  • Loading branch information
xinyuaixiaoyu authored Nov 14, 2023
1 parent dca0001 commit 09f774e
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: number) {
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 09f774e

Please sign in to comment.