Skip to content

Commit 38f6565

Browse files
committed
Functional draft progress bar next to play button for current playing track.
It can be interacted with but the slider behaves incorrectly when the user *slides it* instead of simply clicking somewhere on the bar : this is due to the fact that the value of the slider is updated by querying player API
1 parent 4dc0295 commit 38f6565

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

Diff for: main.ts

+55
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ export default class SoundscapesPlugin extends Plugin {
4343
playButton: HTMLButtonElement;
4444
pauseButton: HTMLButtonElement;
4545
nextButton: HTMLButtonElement;
46+
trackProgressSlider: HTMLInputElement;
47+
progressDuration : HTMLDivElement;
4648
previousButton: HTMLButtonElement;
4749
changeSoundscapeSelect: HTMLSelectElement;
4850
nowPlayingRoot: HTMLDivElement;
@@ -366,6 +368,29 @@ export default class SoundscapesPlugin extends Plugin {
366368
setIcon(this.nextButton, "skip-forward");
367369
this.nextButton.onclick = () => this.next();
368370

371+
// Progress : Duration
372+
this.progressDuration = this.statusBarItem.createEl("div", {
373+
cls: "soundscapesroot-progress-duration",
374+
});
375+
// Change Button
376+
this.trackProgressSlider = this.statusBarItem.createEl("input", {
377+
attr: {
378+
type: "range",
379+
min: 0,
380+
max: 1,
381+
step: 0.01,
382+
value: this.settings.trackProgress,
383+
class : "trackProgress"
384+
},
385+
});
386+
// Create a virtual event object
387+
this.onTrackProgressChange({ target: { value: this.settings.trackProgress } });
388+
389+
this.trackProgressSlider.addEventListener(
390+
"input",
391+
this.onTrackProgressChange.bind(this)
392+
)
393+
369394
// Change Soundscape Button
370395
const changeSoundscapeButton = this.statusBarItem.createEl("button", {
371396
cls: "soundscapesroot-changesoundscapebutton",
@@ -479,6 +504,7 @@ export default class SoundscapesPlugin extends Plugin {
479504
* Plays the current track. When it's a live video, attempt to jump to the "live" portion.
480505
*/
481506
play() {
507+
var self = this;
482508
if (
483509
this.soundscapeType === SOUNDSCAPE_TYPE.STANDARD &&
484510
SOUNDSCAPES[this.settings.soundscape].isLiveVideo
@@ -613,6 +639,9 @@ export default class SoundscapesPlugin extends Plugin {
613639
seek(time: number) {
614640
if (this.soundscapeType === SOUNDSCAPE_TYPE.MY_MUSIC) {
615641
this.localPlayer.currentTime = time;
642+
} else {
643+
var t= this.player?.getCurrentTime();
644+
this.player?.seekTo(t+time);
616645
}
617646
}
618647

@@ -691,8 +720,26 @@ export default class SoundscapesPlugin extends Plugin {
691720
* Once the player is ready, create the controls and play some music! (or not if autoplay is disabled)
692721
*/
693722
onPlayerReady() {
723+
var self = this
694724
this.createControls();
695725
this.onSoundscapeChange(this.settings.autoplay);
726+
setInterval(function() {
727+
var progress = (self.player?.getCurrentTime()/self.player?.getDuration()).toFixed(5)
728+
self.trackProgressSlider.value = (progress).toString()
729+
self.progressDuration.setText(
730+
(self.formatDate(self.player?.getCurrentTime())+" / "+self.formatDate(self.player?.getDuration()))
731+
)
732+
}, 10);
733+
}
734+
735+
formatDate(duration: number){
736+
if(duration < 3600){
737+
return new Date(duration*1000).toISOString().substring(14, 19)
738+
}else if(duration <3600*24){
739+
return new Date(duration*1000).toISOString().substring(11, 19)
740+
}else{
741+
return Math.round(duration/(3600*24)) +":"+ new Date(duration*1000).toISOString().substring(11, 19)
742+
}
696743
}
697744

698745
/**
@@ -777,6 +824,14 @@ export default class SoundscapesPlugin extends Plugin {
777824
this.debouncedSaveSettings();
778825
}
779826

827+
onTrackProgressChange(e: any) {
828+
const trackProgress = parseFloat(e.target.value);
829+
this.trackProgressSlider.value = e.target.value;
830+
this.player?.seekTo(this.player.getDuration()*(trackProgress));
831+
this.settings.trackProgress = trackProgress;
832+
this.settingsObservable.setValue(this.settings);
833+
this.debouncedSaveSettings();
834+
}
780835
/**
781836
* Play the selected soundscape!
782837
*

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/Settings/Settings.ts

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface SoundscapesPluginSettings {
1414
autoplay: boolean;
1515
scrollSongTitle: boolean;
1616
customSoundscapes: CustomSoundscape[];
17+
trackProgress: number;
1718
myMusicIndex: LocalMusicFile[];
1819
myMusicFolderPath: string;
1920
reindexFrequency: string;
@@ -26,6 +27,7 @@ export const DEFAULT_SETTINGS: SoundscapesPluginSettings = {
2627
volume: 25,
2728
autoplay: false,
2829
scrollSongTitle: true,
30+
trackProgress: 0,
2931
customSoundscapes: [],
3032
myMusicIndex: [],
3133
myMusicFolderPath: "",

Diff for: src/Types/Interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface Player {
2828
getDuration(): number;
2929
setVolume(volume: Number): void;
3030
loadVideoById(options: { videoId: String | undefined }): void;
31+
getCurrentTime():number;
3132
}
3233

3334
export interface LocalMusicFile {

Diff for: styles.scss

+10
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@
6161
right: 0;
6262
}
6363

64+
.soundscapesroot-progress-duration{
65+
margin: 10px;
66+
width: auto;
67+
white-space: nowrap;
68+
}
69+
6470
.soundscapesroot-nowplaying {
6571
margin: 0 12px;
6672
width: 150px;
@@ -79,6 +85,10 @@
7985
}
8086
}
8187
}
88+
89+
.trackProgress{
90+
width: 100%;
91+
}
8292
}
8393

8494
input.soundscapes-validation-error {

0 commit comments

Comments
 (0)