@@ -67,13 +67,33 @@ class Wavesurfer extends Component {
6767 options . backend = 'MediaElement' ;
6868 }
6969
70+ // Do not draw waveform behind translucent progress waveform.
71+
7072 this . _wavesurfer = WaveSurfer . create ( options ) ;
7173
7274 this . _wavesurfer . drawer . updateProgress = function ( position ) {
7375 this . style ( this . progressWave , { width : position + 'px' } ) ;
7476 this . style ( this . wrapper . lastChild , { clipPath : 'rect(auto auto auto ' + position + 'px)' } ) ;
7577 }
7678
79+ // Prevent Wavesurfer from calling load on media element when peak
80+ // data is present. Otherwise play progress is reset lazy loading
81+ // re-initializes the player after having moved off-screen.
82+ // Wavesurfer already skips that if preload is"none". We can thus
83+ // use this to suppress the unwanted load. If media is already
84+ // playing, we need to fire play event to make Wavesurfer start
85+ // the timer that updates waveform progress.
86+
87+ const origLoad = this . _wavesurfer . backends . MediaElement . prototype . _load ;
88+
89+ this . _wavesurfer . backends . MediaElement . prototype . _load = function ( media , peaks ) {
90+ origLoad . call ( this , media , peaks , 'none' ) ;
91+
92+ if ( ! media . paused ) {
93+ this . fireEvent ( 'play' ) ;
94+ }
95+ }
96+
7797 // file was loaded, wave was drawn
7898 this . _wavesurfer . on ( 'ready' , ( ) => {
7999 this . setState ( {
0 commit comments