Change playSong method to consume song object rather than queue ID
This commit is contained in:
parent
3b3b7773db
commit
8f429f0847
2 changed files with 12 additions and 12 deletions
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
{#snippet playerQueue()}
|
{#snippet playerQueue()}
|
||||||
{#each queue as song, idx}
|
{#each queue as song, idx}
|
||||||
<p onclick={() => playSong(idx)}>{song.artist} - {song.title} ({timeFormat(song.duration)})<Button onclick={() => removeSongFromQueue(idx)}>X</Button></p>
|
<p onclick={() => playSong(song, idx)}>{song.artist} - {song.title} ({timeFormat(song.duration)})<Button onclick={() => removeSongFromQueue(idx)}>X</Button></p>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<Button onclick={() => queue.push(queue[0])}>Add</Button>
|
<Button onclick={() => queue.push(queue[0])}>Add</Button>
|
||||||
|
|
|
@ -54,11 +54,16 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function playSong(songIndex: number) {
|
function playSong(song: unknown, songIndex: number) {
|
||||||
console.log(queue[songIndex].title);
|
//const chosenSong = queue[songIndex];
|
||||||
const chosenSong = queue[songIndex];
|
pause();
|
||||||
|
newSong(song);
|
||||||
|
play();
|
||||||
|
}
|
||||||
|
|
||||||
|
function newSong(song: number) {
|
||||||
let parameters = [
|
let parameters = [
|
||||||
{ parameter: "id", value: chosenSong.id },
|
{ parameter: "id", value: song.id },
|
||||||
//{ parameter: "maxBitRate", value: } // TODO
|
//{ parameter: "maxBitRate", value: } // TODO
|
||||||
//{ parameter: "format", value: } // TODO
|
//{ parameter: "format", value: } // TODO
|
||||||
//{ parameter: "timeOffset", value: } // TODO? Only Video related
|
//{ parameter: "timeOffset", value: } // TODO? Only Video related
|
||||||
|
@ -67,13 +72,6 @@
|
||||||
//{ parameter: "converted", value: } // TODO? Only Video related
|
//{ parameter: "converted", value: } // TODO? Only Video related
|
||||||
];
|
];
|
||||||
let url = OpenSubsonic.getApiUrl("stream", parameters);
|
let url = OpenSubsonic.getApiUrl("stream", parameters);
|
||||||
|
|
||||||
pause();
|
|
||||||
newSong(url);
|
|
||||||
play();
|
|
||||||
}
|
|
||||||
|
|
||||||
function newSong(url: string) {
|
|
||||||
source = new Audio(url); // Assign new URL
|
source = new Audio(url); // Assign new URL
|
||||||
|
|
||||||
// Reassign Event Handlers
|
// Reassign Event Handlers
|
||||||
|
@ -93,6 +91,8 @@
|
||||||
source.ontimeupdate = () => {
|
source.ontimeupdate = () => {
|
||||||
progress = source.currentTime;
|
progress = source.currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
source.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
function play() {
|
function play() {
|
||||||
|
|
Loading…
Reference in a new issue