diff --git a/src/components/engine/audio/element.js b/src/components/engine/audio/element.js index 6165a2fb..b9e3e666 100644 --- a/src/components/engine/audio/element.js +++ b/src/components/engine/audio/element.js @@ -25,6 +25,13 @@ const SILENT_MP3 = class AudioEngine extends BroadcastableDiffuseElement { static NAME = "diffuse/engine/audio"; + constructor() { + super(); + + this.isPlaying = this.isPlaying.bind(this); + this.state = this.state.bind(this); + } + // SIGNALS #items = signal(/** @type {Audio[]} */ ([])); @@ -243,6 +250,21 @@ class AudioEngine extends BroadcastableDiffuseElement { // 🛠️ + /** + * Convenience signal to track if something is, or was, playing. + */ + _isPlaying() { + return computed(() => { + const item = this.items()?.[0]; + if (!item) return false; + + const state = this.state(item.id); + if (!state) return false; + + return state.isPlaying() || state.hasEnded() || state.progress() === 1; + }); + } + /** * Get the state of a single audio item. * @@ -262,15 +284,7 @@ class AudioEngine extends BroadcastableDiffuseElement { * Convenience signal to track if something is, or was, playing. */ isPlaying() { - return computed(() => { - const item = this.items()?.[0]; - if (!item) return false; - - const state = this.state(item.id); - if (!state) return false; - - return state.isPlaying() || state.hasEnded() || state.progress() === 1; - }); + return this._isPlaying()(); } /** diff --git a/src/components/orchestrator/queue-audio/element.js b/src/components/orchestrator/queue-audio/element.js index 59c89127..4ed65b6c 100644 --- a/src/components/orchestrator/queue-audio/element.js +++ b/src/components/orchestrator/queue-audio/element.js @@ -50,7 +50,7 @@ class QueueAudioOrchestrator extends DiffuseElement { if (!this.queue) return; const activeTrack = this.queue.now(); - const isPlaying = untracked(this.audio.isPlaying()); + const isPlaying = untracked(this.audio.isPlaying); // Resolve URIs const resolvedUri = activeTrack diff --git a/src/themes/blur/artwork-controller/element.js b/src/themes/blur/artwork-controller/element.js index 1d43a1f4..0ee6eb2a 100644 --- a/src/themes/blur/artwork-controller/element.js +++ b/src/themes/blur/artwork-controller/element.js @@ -76,7 +76,7 @@ class ArtworkController extends DiffuseElement { }); #isPlaying = computed(() => { - return this.$audio.value?.isPlaying()(); + return this.$audio.value?.isPlaying(); }); // LIFECYCLE