Skip to content

Commit

Permalink
cannot play without src
Browse files Browse the repository at this point in the history
  • Loading branch information
bartbutenaers committed Dec 4, 2024
1 parent 95a9d8a commit eb0438a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
20 changes: 20 additions & 0 deletions nodes/widgets/ui_audio.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const datastore = require('../store/data.js')
const statestore = require('../store/state.js')

module.exports = function (RED) {
Expand All @@ -11,7 +12,26 @@ module.exports = function (RED) {

const evts = {
onAction: true,
onInput: function (msg, send) {
// store the latest msg passed to node, only if a source is supplied in the payload
if (typeof msg.payload === 'string') {
datastore.save(group.getBase(), node, msg)
}
// only send msg on if we have passthru enabled
if (config.passthru) {
send(msg)
}
},
beforeSend: function (msg) {
if (msg.playback === 'play') {
const lastMsg = datastore.get(node.id)
// TODO zou eigenlijk de last message met een payload moeten zijn.
const src = lastMsg?.payload || config.src
if (typeof src !== 'string' || src.trim() === '') {
node.warn('Cannot play audio when no source has been specified')
}
}

if (msg.ui_update) {
const updates = msg.ui_update

Expand Down
8 changes: 6 additions & 2 deletions ui/src/widgets/ui-audio/UIAudio.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ export default {
switch (msg.playback) {
case 'play':
this.$refs.audio.play()
this.$refs.audio.play().catch((err) => {
console.error('Error playing audio:', err)
})
break
case 'stop':
this.$refs.audio.src = ''
break
case 'pause':
this.$refs.audio.pause()
this.$refs.audio.pause().catch((err) => {
console.error('Error pausing audio:', err)
})
break
}
},
Expand Down

0 comments on commit eb0438a

Please sign in to comment.