@@ -43,6 +43,8 @@ export default class SoundscapesPlugin extends Plugin {
43
43
playButton : HTMLButtonElement ;
44
44
pauseButton : HTMLButtonElement ;
45
45
nextButton : HTMLButtonElement ;
46
+ trackProgressSlider : HTMLInputElement ;
47
+ progressDuration : HTMLDivElement ;
46
48
previousButton : HTMLButtonElement ;
47
49
changeSoundscapeSelect : HTMLSelectElement ;
48
50
nowPlayingRoot : HTMLDivElement ;
@@ -366,6 +368,29 @@ export default class SoundscapesPlugin extends Plugin {
366
368
setIcon ( this . nextButton , "skip-forward" ) ;
367
369
this . nextButton . onclick = ( ) => this . next ( ) ;
368
370
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
+
369
394
// Change Soundscape Button
370
395
const changeSoundscapeButton = this . statusBarItem . createEl ( "button" , {
371
396
cls : "soundscapesroot-changesoundscapebutton" ,
@@ -613,6 +638,9 @@ export default class SoundscapesPlugin extends Plugin {
613
638
seek ( time : number ) {
614
639
if ( this . soundscapeType === SOUNDSCAPE_TYPE . MY_MUSIC ) {
615
640
this . localPlayer . currentTime = time ;
641
+ } else {
642
+ var t = this . player ?. getCurrentTime ( ) ;
643
+ this . player ?. seekTo ( t + time ) ;
616
644
}
617
645
}
618
646
@@ -691,8 +719,26 @@ export default class SoundscapesPlugin extends Plugin {
691
719
* Once the player is ready, create the controls and play some music! (or not if autoplay is disabled)
692
720
*/
693
721
onPlayerReady ( ) {
722
+ var self = this
694
723
this . createControls ( ) ;
695
724
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
+ }
696
742
}
697
743
698
744
/**
@@ -777,6 +823,14 @@ export default class SoundscapesPlugin extends Plugin {
777
823
this . debouncedSaveSettings ( ) ;
778
824
}
779
825
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
+ }
780
834
/**
781
835
* Play the selected soundscape!
782
836
*
0 commit comments