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