Skip to content

Commit

Permalink
[webaudio] Allow stopping play
Browse files Browse the repository at this point in the history
Use of a dictionary to store audio sources currently playing and stop them all when asked to. A corresponding core (webaudio sink) modification is following.
Signed-off-by: Gwendal Roulleau <gwendal.roulleau@gmail.com>
  • Loading branch information
dalgwen committed Aug 20, 2023
1 parent a08c347 commit 393fe6a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bundles/org.openhab.ui/web/src/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export default {
ready: false,
eventSource: null,
audioContext: null,
audioSources: new Map(),
// Framework7 Parameters
f7params: {
Expand Down Expand Up @@ -631,6 +632,13 @@ export default {
},
playAudioUrl (audioUrl) {
try {
if (audioUrl === '') {
this.audioSources.forEach(function (value, key) {
value.stop(0)
})
this.audioSources.clear()
return
}
if (!this.audioContext) {
window.AudioContext = window.AudioContext || window.webkitAudioContext
if (typeof (window.AudioContext) !== 'undefined') {
Expand All @@ -644,6 +652,12 @@ export default {
let source = this.audioContext.createBufferSource()
source.buffer = buffer
source.connect(this.audioContext.destination)
let customId = Date.now().toString()
this.audioSources.set(customId, source)
source.onended = () => {
source.stop(0)
this.audioSources.delete(customId)
}
source.start(0)
})
})
Expand Down

0 comments on commit 393fe6a

Please sign in to comment.