koel/resources/assets/js/services/audioService.ts

30 lines
728 B
TypeScript
Raw Normal View History

2022-04-24 08:50:45 +00:00
export const audioService = {
2022-04-15 14:24:30 +00:00
context: null as AudioContext | null,
source: null as MediaElementAudioSourceNode | null,
element: null as HTMLMediaElement | null,
init (element: HTMLMediaElement): void {
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 (): AudioContext {
return this.context!
},
getSource (): MediaElementAudioSourceNode {
return this.source!
},
getElement (): HTMLMediaElement {
return this.element!
}
}