From d6bc4fd301308aa5f803a9305725c8ac75c5816e Mon Sep 17 00:00:00 2001 From: Marks Polakovs Date: Wed, 25 Mar 2020 15:07:24 +0100 Subject: [PATCH] Lock out playback controls while loading (fixes #20) --- src/mixer/state.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/mixer/state.ts b/src/mixer/state.ts index 0e27282..f8c668f 100644 --- a/src/mixer/state.ts +++ b/src/mixer/state.ts @@ -370,19 +370,27 @@ export const load = ( wavesurfers[player] = wavesurfer; }; -export const play = (player: number): AppThunk => dispatch => { +export const play = (player: number): AppThunk => (dispatch, getState) => { if (typeof wavesurfers[player] === "undefined") { console.log("nothing loaded"); return; } + if (getState().mixer.players[player].loading) { + console.log("not ready"); + return; + } wavesurfers[player].play(); }; -export const pause = (player: number): AppThunk => dispatch => { +export const pause = (player: number): AppThunk => (dispatch, getState) => { if (typeof wavesurfers[player] === "undefined") { console.log("nothing loaded"); return; } + if (getState().mixer.players[player].loading) { + console.log("not ready"); + return; + } if (wavesurfers[player].isPlaying()) { wavesurfers[player].pause(); } else { @@ -390,11 +398,15 @@ export const pause = (player: number): AppThunk => dispatch => { } }; -export const stop = (player: number): AppThunk => dispatch => { +export const stop = (player: number): AppThunk => (dispatch, getState) => { if (typeof wavesurfers[player] === "undefined") { console.log("nothing loaded"); return; } + if (getState().mixer.players[player].loading) { + console.log("not ready"); + return; + } wavesurfers[player].stop(); };