Lock out playback controls while loading (fixes #20)

This commit is contained in:
Marks Polakovs 2020-03-25 15:07:24 +01:00
parent 5dad5e2384
commit d6bc4fd301

View file

@ -370,19 +370,27 @@ export const load = (
wavesurfers[player] = wavesurfer; wavesurfers[player] = wavesurfer;
}; };
export const play = (player: number): AppThunk => dispatch => { export const play = (player: number): AppThunk => (dispatch, getState) => {
if (typeof wavesurfers[player] === "undefined") { if (typeof wavesurfers[player] === "undefined") {
console.log("nothing loaded"); console.log("nothing loaded");
return; return;
} }
if (getState().mixer.players[player].loading) {
console.log("not ready");
return;
}
wavesurfers[player].play(); wavesurfers[player].play();
}; };
export const pause = (player: number): AppThunk => dispatch => { export const pause = (player: number): AppThunk => (dispatch, getState) => {
if (typeof wavesurfers[player] === "undefined") { if (typeof wavesurfers[player] === "undefined") {
console.log("nothing loaded"); console.log("nothing loaded");
return; return;
} }
if (getState().mixer.players[player].loading) {
console.log("not ready");
return;
}
if (wavesurfers[player].isPlaying()) { if (wavesurfers[player].isPlaying()) {
wavesurfers[player].pause(); wavesurfers[player].pause();
} else { } 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") { if (typeof wavesurfers[player] === "undefined") {
console.log("nothing loaded"); console.log("nothing loaded");
return; return;
} }
if (getState().mixer.players[player].loading) {
console.log("not ready");
return;
}
wavesurfers[player].stop(); wavesurfers[player].stop();
}; };