tangled
alpha
login
or
join now
tokono.ma
/
diffuse
5
fork
atom
A music player that connects to your cloud/distributed storage.
5
fork
atom
overview
issues
4
pulls
pipelines
refactor: isPlaying
Steven Vandevelde
3 months ago
de03e4cd
3f0c795b
+25
-11
3 changed files
expand all
collapse all
unified
split
src
components
engine
audio
element.js
orchestrator
queue-audio
element.js
themes
blur
artwork-controller
element.js
+23
-9
src/components/engine/audio/element.js
···
25
25
class AudioEngine extends BroadcastableDiffuseElement {
26
26
static NAME = "diffuse/engine/audio";
27
27
28
28
+
constructor() {
29
29
+
super();
30
30
+
31
31
+
this.isPlaying = this.isPlaying.bind(this);
32
32
+
this.state = this.state.bind(this);
33
33
+
}
34
34
+
28
35
// SIGNALS
29
36
30
37
#items = signal(/** @type {Audio[]} */ ([]));
···
244
251
// 🛠️
245
252
246
253
/**
254
254
+
* Convenience signal to track if something is, or was, playing.
255
255
+
*/
256
256
+
_isPlaying() {
257
257
+
return computed(() => {
258
258
+
const item = this.items()?.[0];
259
259
+
if (!item) return false;
260
260
+
261
261
+
const state = this.state(item.id);
262
262
+
if (!state) return false;
263
263
+
264
264
+
return state.isPlaying() || state.hasEnded() || state.progress() === 1;
265
265
+
});
266
266
+
}
267
267
+
268
268
+
/**
247
269
* Get the state of a single audio item.
248
270
*
249
271
* @param {string} audioId
···
262
284
* Convenience signal to track if something is, or was, playing.
263
285
*/
264
286
isPlaying() {
265
265
-
return computed(() => {
266
266
-
const item = this.items()?.[0];
267
267
-
if (!item) return false;
268
268
-
269
269
-
const state = this.state(item.id);
270
270
-
if (!state) return false;
271
271
-
272
272
-
return state.isPlaying() || state.hasEnded() || state.progress() === 1;
273
273
-
});
287
287
+
return this._isPlaying()();
274
288
}
275
289
276
290
/**
+1
-1
src/components/orchestrator/queue-audio/element.js
···
50
50
if (!this.queue) return;
51
51
52
52
const activeTrack = this.queue.now();
53
53
-
const isPlaying = untracked(this.audio.isPlaying());
53
53
+
const isPlaying = untracked(this.audio.isPlaying);
54
54
55
55
// Resolve URIs
56
56
const resolvedUri = activeTrack
+1
-1
src/themes/blur/artwork-controller/element.js
···
76
76
});
77
77
78
78
#isPlaying = computed(() => {
79
79
-
return this.$audio.value?.isPlaying()();
79
79
+
return this.$audio.value?.isPlaying();
80
80
});
81
81
82
82
// LIFECYCLE