Skip to content

Commit 3ffdb5f

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 3ffdb5f

File tree

5 files changed

+69
-2
lines changed

5 files changed

+69
-2
lines changed

Diff for: main.ts

+54
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",
@@ -613,6 +638,9 @@ export default class SoundscapesPlugin extends Plugin {
613638
seek(time: number) {
614639
if (this.soundscapeType === SOUNDSCAPE_TYPE.MY_MUSIC) {
615640
this.localPlayer.currentTime = time;
641+
} else {
642+
var t= this.player?.getCurrentTime();
643+
this.player?.seekTo(t+time);
616644
}
617645
}
618646

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

698744
/**
@@ -777,6 +823,14 @@ export default class SoundscapesPlugin extends Plugin {
777823
this.debouncedSaveSettings();
778824
}
779825

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

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)