Skip to content

Commit fd5d91e

Browse files
committed
fix playlists
1 parent 71078c1 commit fd5d91e

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

client/public/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"buildMajor":1,"buildMinor":125,"buildRevision":345,"buildTag":"dev","buildDate":"Sun Sep 21 2025","build":"1.125.345 dev"}
1+
{"buildMajor":1,"buildMinor":125,"buildRevision":346,"buildTag":"dev","buildDate":"Mon Nov 24 2025","build":"1.125.346 dev"}

client/src/client/medialib/MediaTrack.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { TimeService } from '../services/time/TimeService';
2+
import { AudioSourceProcessor } from '../util/AudioSourceProcessor';
23

34
export class MediaTrack {
45
constructor({
@@ -18,6 +19,7 @@ export class MediaTrack {
1819
this.startInstant = startInstant || null;
1920
this.speedPct = speedPct || 100;
2021
this.muted = !!muted;
22+
this.sourceRewriter = new AudioSourceProcessor();
2123

2224
this.audio = providedAudio || new Audio();
2325
// Prefer eager metadata loading so we can compute duration/start offsets early
@@ -32,6 +34,8 @@ export class MediaTrack {
3234
console.warn('Replacing audio src', this.audio.src, 'with', source);
3335
this.audio.src = source;
3436
}
37+
38+
// this is not supported enough
3539
this.audio.loop = !!loop;
3640

3741
this.epoch = 0;
@@ -42,6 +46,33 @@ export class MediaTrack {
4246
this._handlers = { ended: null, error: null };
4347
}
4448

49+
setPlaylist(playlistArray) {
50+
if (this.audio.loop) {
51+
this.audio.loop = false;
52+
this.currentSongIndex = playlistArray.length - 1;
53+
this.audio.addEventListener('ended', () => {
54+
let nextIndex = this.currentSongIndex + 1;
55+
if (nextIndex >= playlistArray.length) {
56+
if (this.loop) {
57+
nextIndex = 0;
58+
this.currentSongIndex = 0;
59+
} else {
60+
return;
61+
}
62+
}
63+
this.currentSongIndex = nextIndex;
64+
65+
const nextSource = playlistArray[nextIndex];
66+
this.sourceRewriter.translate(nextSource).then((translatedSrc) => {
67+
// have we not been stopped/destroyed in the meantime?
68+
if (this.state === 'destroyed' || this.state === 'stopped') return;
69+
this.audio.src = translatedSrc;
70+
this.audio.play();
71+
});
72+
});
73+
}
74+
}
75+
4576
setTimerInterval(fn, ms) {
4677
const id = setInterval(fn, ms);
4778
this.timers.add(id);
@@ -101,6 +132,7 @@ export class MediaTrack {
101132
const onErr = endGuard(() => {
102133
});
103134
const onEnd = endGuard(() => {
135+
if (this.loop) return;
104136
this.onFinish.forEach((cb) => {
105137
try {
106138
cb();

client/src/client/services/media/objects/Sound.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ export class Sound extends AudioSourceProcessor {
203203
}
204204

205205
this.soundElement.onended = async () => {
206+
console.log('onended');
206207
if (this.gotShutDown) return;
207208
if (!this.finsishedInitializing) return;
208209

@@ -219,6 +220,7 @@ export class Sound extends AudioSourceProcessor {
219220
}
220221

221222
if (this.loop && !this.gotShutDown) {
223+
console.log('looping sound');
222224
try {
223225
// possibly fetch next playlist entry
224226
const nextSource = await this.translate(this.rawSource);
@@ -238,6 +240,7 @@ export class Sound extends AudioSourceProcessor {
238240
if (this._track) await this._track.play();
239241
}
240242
} catch (error) {
243+
console.error('error');
241244
debugLog('Error handling loop:', error);
242245
}
243246
} else if (!this.gotShutDown) {

client/src/client/services/socket/handlers/HandleCreateMedia.jsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ export async function handleCreateMedia(data) {
2929

3030
await MEDIA_MUTEX.lock();
3131
const initialSource = source;
32+
const isPlaylist = source.startsWith('[') && source.endsWith(']');
33+
3234
source = await sourceRewriter.translate(source);
33-
console.log(`translaged source ${initialSource} to ${source}`);
35+
3436
let preloaded;
35-
try {
36-
preloaded = await AudioPreloader.getResource(source, false, true);
37-
} catch (e) {
38-
console.error(`Failed to load audio from ${source}`, e);
39-
MEDIA_MUTEX.unlock();
40-
return;
37+
if (!isPlaylist) {
38+
try {
39+
preloaded = await AudioPreloader.getResource(source, false, true);
40+
} catch (e) {
41+
console.error(`Failed to load audio from ${source}`, e);
42+
MEDIA_MUTEX.unlock();
43+
return;
44+
}
4145
}
4246

4347
// only if its a new version and provided, then use that volume
@@ -76,6 +80,10 @@ export async function handleCreateMedia(data) {
7680
id: `${id}::0`, source, audio: preloaded, loop: looping, startAtMillis, startInstant,
7781
});
7882

83+
if (isPlaylist) {
84+
track.setPlaylist(JSON.parse(initialSource));
85+
}
86+
7987
if (speed != null && speed !== 1 && speed !== 0) track.setPlaybackSpeed(speed);
8088
newChannel.addTrack(track);
8189
if (!looping) {

client/src/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"buildMajor":1,"buildMinor":125,"buildRevision":345,"buildTag":"dev","buildDate":"Sun Sep 21 2025","build":"1.125.345 dev"}
1+
{"buildMajor":1,"buildMinor":125,"buildRevision":346,"buildTag":"dev","buildDate":"Mon Nov 24 2025","build":"1.125.346 dev"}

0 commit comments

Comments
 (0)