@@ -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" ,
@@ -479,6 +504,7 @@ export default class SoundscapesPlugin extends Plugin {
479
504
* Plays the current track. When it's a live video, attempt to jump to the "live" portion.
480
505
*/
481
506
play ( ) {
507
+ var self = this ;
482
508
if (
483
509
this . soundscapeType === SOUNDSCAPE_TYPE . STANDARD &&
484
510
SOUNDSCAPES [ this . settings . soundscape ] . isLiveVideo
@@ -613,6 +639,9 @@ export default class SoundscapesPlugin extends Plugin {
613
639
seek ( time : number ) {
614
640
if ( this . soundscapeType === SOUNDSCAPE_TYPE . MY_MUSIC ) {
615
641
this . localPlayer . currentTime = time ;
642
+ } else {
643
+ var t = this . player ?. getCurrentTime ( ) ;
644
+ this . player ?. seekTo ( t + time ) ;
616
645
}
617
646
}
618
647
@@ -691,8 +720,26 @@ export default class SoundscapesPlugin extends Plugin {
691
720
* Once the player is ready, create the controls and play some music! (or not if autoplay is disabled)
692
721
*/
693
722
onPlayerReady ( ) {
723
+ var self = this
694
724
this . createControls ( ) ;
695
725
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
+ }
696
743
}
697
744
698
745
/**
@@ -777,6 +824,14 @@ export default class SoundscapesPlugin extends Plugin {
777
824
this . debouncedSaveSettings ( ) ;
778
825
}
779
826
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
+ }
780
835
/**
781
836
* Play the selected soundscape!
782
837
*
0 commit comments