@@ -258,6 +258,9 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
258258 ) ;
259259 }
260260 } catch ( error ) {
261+ // If the player is not prepared, triggering the stop will reset the player for next click
262+ await stopPlayerAction ( ) ;
263+
261264 return Promise . reject ( error ) ;
262265 }
263266 } else {
@@ -423,7 +426,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
423426 // eslint-disable-next-line react-hooks/exhaustive-deps
424427 } , [ viewLayout ?. width , mode , candleWidth , candleSpace ] ) ;
425428
426- useEffect ( ( ) => {
429+ const seekToPlayerAction = async ( ) => {
427430 if ( ! isNil ( seekPosition ) ) {
428431 if ( mode === 'static' ) {
429432 const seekAmount =
@@ -432,10 +435,16 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
432435 const clampedSeekAmount = clamp ( seekAmount , 0 , 1 ) ;
433436
434437 if ( ! panMoving ) {
435- seekToPlayer ( {
436- playerKey : `PlayerFor${ path } ` ,
437- progress : clampedSeekAmount * songDuration ,
438- } ) ;
438+ try {
439+ await seekToPlayer ( {
440+ playerKey : `PlayerFor${ path } ` ,
441+ progress : clampedSeekAmount * songDuration ,
442+ } ) ;
443+ } catch ( e ) {
444+ // If the player is not prepared, triggering the stop will reset the player for next click
445+ await stopPlayerAction ( ) ;
446+ }
447+
439448 if ( playerState === PlayerState . playing ) {
440449 startPlayerAction ( ) ;
441450 }
@@ -444,6 +453,10 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
444453 setCurrentProgress ( clampedSeekAmount * songDuration ) ;
445454 }
446455 }
456+ } ;
457+
458+ useEffect ( ( ) => {
459+ seekToPlayerAction ( ) ;
447460 // eslint-disable-next-line react-hooks/exhaustive-deps
448461 } , [ seekPosition , panMoving , mode , songDuration ] ) ;
449462
0 commit comments