diff --git a/src/lib/components/custom/PlayerControls.svelte b/src/lib/components/custom/PlayerControls.svelte
index fcaa5d9..9fdf15f 100644
--- a/src/lib/components/custom/PlayerControls.svelte
+++ b/src/lib/components/custom/PlayerControls.svelte
@@ -62,7 +62,8 @@
{/if}
-
+
+
{:else}
Nothing going on here
diff --git a/src/lib/states/play-queue.svelte.ts b/src/lib/states/play-queue.svelte.ts
index acaef3b..a576428 100644
--- a/src/lib/states/play-queue.svelte.ts
+++ b/src/lib/states/play-queue.svelte.ts
@@ -16,6 +16,7 @@ interface QueueState {
firstSong: () => Song,
findSong: (song: Song) => {found: boolean, index: number},
addSong: (song: Song) => void,
+ replaceQueue: (newQueue: Array) => void,
getPlayQueue: (addNowPlaying: boolean) => Promise,
saveQueue: () => Promise,
}
@@ -55,6 +56,11 @@ export const queueState: QueueState = $state({
this.queue.push(newSong);
this.currentIndex = this.queue.length - 1;
},
+ replaceQueue(newQueue: Array): void {
+ console.log(newQueue)
+ this.queue = [...newQueue];
+ this.currentIndex = 0;
+ },
async getPlayQueue(addNowPlaying: boolean = false): Promise {
const queueData: GetPlayQueueResponse = await OpenSubsonic.get("getPlayQueue")
if (queueData && queueData.playQueue.entry) {
diff --git a/src/lib/states/playback-state.svelte.ts b/src/lib/states/playback-state.svelte.ts
index 9c87d1b..cea39a0 100644
--- a/src/lib/states/playback-state.svelte.ts
+++ b/src/lib/states/playback-state.svelte.ts
@@ -2,8 +2,17 @@ import {PlaybackMode, PlaybackStateSvelte} from "$lib/player.svelte";
import {OpenSubsonic, type Parameter, type Song} from "$lib/opensubsonic";
import {queueState} from "$lib/states/play-queue.svelte";
+export const shuffle = (array: Array) => {
+ for (let i: number = array.length - 1; i > 0; i--) {
+ const j: number = Math.floor(Math.random() * (i + 1));
+ [array[i], array[j]] = [array[j], array[i]];
+ }
+ return array;
+};
+
interface PlaybackState {
- mode: PlaybackStateSvelte,
+ loopMode: PlaybackStateSvelte,
+ shuffle: boolean,
song: HTMLAudioElement,
metaData: Song,
duration: number,
@@ -16,7 +25,8 @@ interface PlaybackState {
}
export const playbackState: PlaybackState = $state({
- mode: new PlaybackStateSvelte(),
+ loopMode: new PlaybackStateSvelte(),
+ shuffle: false,
song: {},
metaData: {},
duration: 0,
@@ -63,7 +73,7 @@ export const playbackState: PlaybackState = $state({
}
this.song.onended = () => {
- switch (this.mode.current) {
+ switch (this.loopMode.current) {
case PlaybackMode.Linear: {
this.newSong(queueState.nextSong());
this.play();
@@ -75,6 +85,10 @@ export const playbackState: PlaybackState = $state({
}
case PlaybackMode.LoopQueue: {
if (queueState.currentIndex === queueState.queue.length -1) {
+ if (this.shuffle) {
+ const shuffledQueue = shuffle([...queueState.queue])
+ queueState.replaceQueue(shuffledQueue);
+ }
this.newSong(queueState.firstSong());
}
else {
diff --git a/src/routes/album/[albumId]/+page.svelte b/src/routes/album/[albumId]/+page.svelte
new file mode 100644
index 0000000..e69de29
diff --git a/src/routes/album/[albumId]/+page.ts b/src/routes/album/[albumId]/+page.ts
new file mode 100644
index 0000000..e69de29