koel/resources/assets/js/services/audioService.ts
2022-05-14 20:49:45 +02:00

29 lines
670 B
TypeScript

export const audioService = {
context: null as unknown as AudioContext,
source: null as unknown as MediaElementAudioSourceNode,
element: null as unknown as HTMLMediaElement,
init (element: HTMLMediaElement) {
const AudioContext = window.AudioContext ||
window.webkitAudioContext ||
window.mozAudioContext ||
window.oAudioContext ||
window.msAudioContext
this.context = new AudioContext()
this.source = this.context.createMediaElementSource(element)
this.element = element
},
getContext () {
return this.context
},
getSource () {
return this.source
},
getElement () {
return this.element
}
}