WIP: global player pt. 5 svelte bindings
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user