Cache music as mp3 files on startup
This commit is contained in:
1 parent
c819436481
commit
33c9daa58b
11 files changed
+158
-15
No files matched your search
@@ -14,6 +14,8 @@ class MusicPlayer {
|
||||
history = $state<number[]>([]);
|
||||
repeat = $state(false);
|
||||
|
||||
audioElement: HTMLAudioElement | null = null;
|
||||
|
||||
private failedTrackCount = 0;
|
||||
private loading = false;
|
||||
|
||||
@@ -108,7 +110,13 @@ class MusicPlayer {
|
||||
}
|
||||
|
||||
seek(seconds: number) {
|
||||
this.startOffset = Math.max(0, Math.min(Math.floor(seconds), this.duration - 1));
|
||||
const targetSeconds = Math.max(0, Math.min(Math.floor(seconds), this.duration - 1));
|
||||
if (this.currentTrack?.cached && this.audioElement) {
|
||||
this.audioElement.currentTime = targetSeconds;
|
||||
this.paused = false;
|
||||
return;
|
||||
}
|
||||
this.startOffset = targetSeconds;
|
||||
this.elapsedSinceStart = 0;
|
||||
this.streamKey += 1;
|
||||
this.paused = false;
|
||||
|
||||
@@ -4,4 +4,5 @@ export interface Track {
|
||||
artist: string;
|
||||
durationSeconds: number;
|
||||
cover: string;
|
||||
cached: boolean;
|
||||
}
|
||||
Reference in new issue
Block a user