From 18ac5ddc28998083bc122b7f96dae8dcf17f48da Mon Sep 17 00:00:00 2001 From: Caleb Allen Date: Sun, 13 Apr 2025 12:25:05 -0400 Subject: [PATCH] improved seek bar functionality. --- frontend/index.ts | 2 +- .../components/audio-player/audio-player.ts | 8 ++- .../audio-player/seekbar/seek-bar.ts | 53 +++++++++---------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/frontend/index.ts b/frontend/index.ts index 01636ff..2aaa24c 100644 --- a/frontend/index.ts +++ b/frontend/index.ts @@ -1 +1 @@ -import '@components/audio-player/audio-player.ts'; +import '@components/audio-player/audio-player.ts'; \ No newline at end of file diff --git a/frontend/src/components/audio-player/audio-player.ts b/frontend/src/components/audio-player/audio-player.ts index c0e990e..ece91a7 100644 --- a/frontend/src/components/audio-player/audio-player.ts +++ b/frontend/src/components/audio-player/audio-player.ts @@ -2,11 +2,17 @@ import { LitElement, html } from 'lit'; import { customElement } from 'lit/decorators.js'; import './controls/player-controls'; import './seekbar/seek-bar'; +import '@go/player/Player'; +import '@shoelace-style/shoelace/dist/components/icon/icon.js'; + const audioPlayer = () => html`
- +
+ +
+
`; diff --git a/frontend/src/components/audio-player/seekbar/seek-bar.ts b/frontend/src/components/audio-player/seekbar/seek-bar.ts index 1db3a7b..fb82a71 100644 --- a/frontend/src/components/audio-player/seekbar/seek-bar.ts +++ b/frontend/src/components/audio-player/seekbar/seek-bar.ts @@ -9,7 +9,7 @@ const progress = signal(20); @customElement('seek-bar') export class SeekBar extends SignalWatcher(LitElement) { @property() - trackLengthSeconds: number = 100; + progressIntervalMillis: number = 1000; @property() isPlaying: boolean = true; @@ -23,52 +23,49 @@ export class SeekBar extends SignalWatcher(LitElement) { } static override styles = css` sl-range::part(base) { - --track-color-active: yellow; + --track-color-active: red; --track-color-inactive: white; --track-height: 6px; - --track-width: 50% } `; override render() { return html` - + `; } - init(trackLength: number){ - this.trackLengthSeconds = trackLength; + init(interval: number, playing: boolean){ + this.progressIntervalMillis = interval; + if(playing)this.startProgress } - - getSeekBarUpdateIntervalMillis(){ - return this.trackLengthSeconds * 10; - } - - // update progress update interval timer thing - // protected override update(changedProperties: PropertyValues): void { - // if (changedProperties.has("trackLengthSeconds")){ - // this.stopProgress(); - // this.startProgress(); - // } - // if(changedProperties.has("isPlaying")){ - // if(this.isPlaying){ - // this.startProgress(); - // } - // else{ - // this.stopProgress(); - // } - // } - // } stopProgress(){ + this.isPlaying = false; clearInterval(this.timerID); } startProgress(){ - this.timerID = setInterval(this.incrementProgressValue, this.getSeekBarUpdateIntervalMillis()); + this.isPlaying = true; + this.timerID = setInterval(this.incrementProgressValue, this.progressIntervalMillis); } + setProgressValue(val: number){ + if(val < 0) val = 0; + if(val > 100) val = 100; + progress.set(val); + } + + setProgressInterval(intervalMillis: number){ + if(intervalMillis < 10) intervalMillis = 10; + + } async incrementProgressValue(){ - progress.set(progress.get() + 1); + if(progress.get() <100) + { + progress.set(progress.get() + 1); + } } }