WIP: global player pt. 5 svelte bindings

This commit is contained in:
2026-02-10 00:09:41 -08:00
parent 4fb1d7865f
commit cfd45b6815
2 changed files with 36 additions and 73 deletions

View File

@@ -13,23 +13,25 @@ export class AudioContext {
this.audioEl = el;
}
// Bindings will handle state updates, but we need methods to control play/pause
// from other components.
// Since we bind to `this.paused`, toggling it here will trigger the audio element.
play() {
this.audioEl?.play();
this.paused = false;
}
pause() {
this.audioEl?.pause();
this.paused = true;
}
toggle() {
if (this.paused) this.play();
else this.pause();
this.paused = !this.paused;
}
seek(time: number) {
if (this.audioEl) {
this.audioEl.currentTime = Math.max(0, Math.min(time, this.duration));
}
// Seeking is done by updating currentTime, which is bound to the audio element.
this.currentTime = Math.max(0, Math.min(time, this.duration));
}
}