[web] Fix audio not stopping

This commit is contained in:
Alain Nussbaumer
2025-05-10 13:44:27 +02:00
parent 2c517ae8a6
commit a4086ee314
3 changed files with 65 additions and 106 deletions

View File

@@ -44,9 +44,6 @@ export default {
volume: 10
}
},
mounted() {
this.setupAudio()
},
unmounted() {
this.closeAudio()
},
@@ -57,47 +54,37 @@ export default {
closeAudio() {
audio.stop()
this.playing = false
this.loading = false
},
playChannel() {
if (this.playing) {
return
}
this.loading = true
audio.play('/stream.mp3')
audio.setVolume(this.volume / 100)
},
setupAudio() {
const a = audio.setup()
a.addEventListener('waiting', () => {
this.playing = false
this.loading = true
})
a.addEventListener('playing', () => {
this.playing = true
this.loading = false
})
a.addEventListener('ended', () => {
this.playing = false
this.loading = false
})
a.addEventListener('error', () => {
this.closeAudio()
this.notificationsStore.add({
text: this.$t('navigation.stream-error'),
type: 'danger'
this.changeVolume()
const a = audio.audio
if (a) {
a.addEventListener('waiting', () => {
this.playing = false
this.loading = true
})
this.playing = false
this.loading = false
})
a.addEventListener('playing', () => {
this.playing = true
this.loading = false
})
a.addEventListener('ended', () => {
this.playing = false
this.loading = false
})
a.addEventListener('error', () => {
this.closeAudio()
})
}
},
togglePlay() {
if (this.loading) {
return
}
if (this.playing) {
if (this.playing || this.loading) {
this.closeAudio()
} else {
this.playChannel()
}
this.playChannel()
}
}
}