mirror of
https://github.com/owntone/owntone-server.git
synced 2025-07-16 04:11:55 -04:00
[web] Simplify audio library
This commit is contained in:
parent
a4086ee314
commit
b52fd89474
@ -1,16 +1,13 @@
|
|||||||
export default {
|
export default {
|
||||||
audio: null,
|
audio: null,
|
||||||
context: null,
|
|
||||||
source: null,
|
|
||||||
play(url) {
|
play(url) {
|
||||||
this.stop()
|
|
||||||
this.audio = new Audio(`${String(url || '')}?x=${Date.now()}`)
|
this.audio = new Audio(`${String(url || '')}?x=${Date.now()}`)
|
||||||
this.audio.crossOrigin = 'anonymous'
|
this.audio.crossOrigin = 'anonymous'
|
||||||
this.context = new (window.AudioContext || window.webkitAudioContext)()
|
const context = new (window.AudioContext || window.webkitAudioContext)()
|
||||||
this.source = this.context.createMediaElementSource(this.audio)
|
const source = context.createMediaElementSource(this.audio)
|
||||||
this.source.connect(this.context.destination)
|
source.connect(context.destination)
|
||||||
this.audio.addEventListener('canplay', () => {
|
this.audio.addEventListener('canplay', () => {
|
||||||
this.context.resume().then(() => {
|
context.resume().then(() => {
|
||||||
this.audio.play()
|
this.audio.play()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user