Skip to content

Commit

Permalink
Merge pull request #13571 from nextcloud/backport/13563/stable30
Browse files Browse the repository at this point in the history
  • Loading branch information
Antreesy authored Oct 17, 2024
2 parents 7c4c1f1 + a7befea commit a485cdd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
25 changes: 9 additions & 16 deletions src/components/MediaSettings/MediaDevicesSpeakerTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ export default {
}
},

data() {
return {
isPlayingTestSound: false,
}
},

computed: {
isPlayingTestSound() {
return this.soundsStore.audioObjectsPromises.wait !== null
},

buttonLabel() {
return this.isPlayingTestSound
// TRANSLATORS Playing the test sound to check speakers
Expand All @@ -67,23 +65,18 @@ export default {
}
},

beforeDestroy() {
this.soundsStore.pauseAudio('wait')
},

methods: {
t,

playTestSound() {
if (this.isPlayingTestSound) {
this.soundsStore.pauseAudio('wait')
return
}
this.isPlayingTestSound = true
try {
} else {
this.soundsStore.playAudio('wait')
this.soundsStore.audioObjects.wait.addEventListener('ended', () => {
this.isPlayingTestSound = false
}, { once: true })
} catch (error) {
console.error(error)
this.isPlayingTestSound = false
}
},
},
Expand Down
24 changes: 22 additions & 2 deletions src/stores/sounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export const useSoundsStore = defineStore('sounds', {
leave: null,
wait: null,
},
audioObjectsPromises: {
join: null,
leave: null,
wait: null,
},
}),

actions: {
Expand All @@ -51,11 +56,16 @@ export const useSoundsStore = defineStore('sounds', {
if (!this.audioObjectsCreated) {
this.initAudioObjects()
}
this.audioObjects[key].play()
this.audioObjectsPromises[key] = this.audioObjects[key].play()
this.audioObjectsPromises[key].catch(error => {
console.error(error)
})
},

pauseAudio(key) {
this.audioObjects[key]?.pause()
if (this.audioObjectsPromises[key]) {
this.audioObjects[key].pause()
}
},

/**
Expand All @@ -70,6 +80,16 @@ export const useSoundsStore = defineStore('sounds', {
const audio = new Audio(filePath)
audio.load()
audio.volume = volume

audio.addEventListener('pause', () => {
this.audioObjectsPromises[key] = null
audio.currentTime = 0
})

audio.addEventListener('ended', () => {
this.audioObjectsPromises[key] = null
})

Vue.set(this.audioObjects, key, audio)
},

Expand Down

0 comments on commit a485cdd

Please sign in to comment.