Let stop button go back to Cue point, and to 0 on second click.

This commit is contained in:
Matthew Stratford 2020-09-22 03:48:22 +01:00
parent 844ad41721
commit 77fb88c913
2 changed files with 25 additions and 2 deletions

View file

@ -55,6 +55,10 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) {
this.wavesurfer.drawBuffer(); this.wavesurfer.drawBuffer();
} }
setCurrentTime(secs: number) {
this.wavesurfer.setCurrentTime(secs);
}
setIntro(duration: number) { setIntro(duration: number) {
if ("intro" in this.wavesurfer.regions.list) { if ("intro" in this.wavesurfer.regions.list) {
this.wavesurfer.regions.list.intro.end = duration; this.wavesurfer.regions.list.intro.end = duration;
@ -149,6 +153,8 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) {
const wavesurfer = WaveSurfer.create({ const wavesurfer = WaveSurfer.create({
audioContext: engine.audioContext, audioContext: engine.audioContext,
container: "#waveform-" + player.toString(), container: "#waveform-" + player.toString(),
cursorColor: "#777",
cursorWidth: 3,
waveColor: "#CCCCFF", waveColor: "#CCCCFF",
backgroundColor: "#FFFFFF", backgroundColor: "#FFFFFF",
progressColor: "#9999FF", progressColor: "#9999FF",

View file

@ -450,6 +450,7 @@ export const load = (
} }
if (state.loadedItem && "cue" in state.loadedItem) { if (state.loadedItem && "cue" in state.loadedItem) {
playerInstance.setCue(state.loadedItem.cue); playerInstance.setCue(state.loadedItem.cue);
playerInstance.setCurrentTime(state.loadedItem.cue);
} }
if (state.loadedItem && "outro" in state.loadedItem) { if (state.loadedItem && "outro" in state.loadedItem) {
playerInstance.setOutro(state.loadedItem.outro); playerInstance.setOutro(state.loadedItem.outro);
@ -576,7 +577,9 @@ export const pause = (player: number): AppThunk => (dispatch, getState) => {
}; };
export const stop = (player: number): AppThunk => (dispatch, getState) => { export const stop = (player: number): AppThunk => (dispatch, getState) => {
if (typeof audioEngine.players[player] === "undefined") {
const playerInstance = audioEngine.players[player];
if (typeof playerInstance === "undefined") {
console.log("nothing loaded"); console.log("nothing loaded");
return; return;
} }
@ -585,7 +588,21 @@ export const stop = (player: number): AppThunk => (dispatch, getState) => {
console.log("not ready"); console.log("not ready");
return; return;
} }
audioEngine.players[player]?.stop();
let cueTime = 0;
console.log(Math.round(playerInstance.currentTime));
if (state.loadedItem && "cue" in state.loadedItem && Math.round(playerInstance.currentTime) !== Math.round(state.loadedItem.cue)) {
cueTime = state.loadedItem.cue;
console.log(cueTime);
}
playerInstance.stop();
dispatch(mixerState.actions.setTimeCurrent({ player, time: cueTime}))
playerInstance.setCurrentTime(cueTime);
// Incase wavesurver wasn't playing, it won't 'finish', so just make sure the UI is stopped. // Incase wavesurver wasn't playing, it won't 'finish', so just make sure the UI is stopped.
dispatch(mixerState.actions.setPlayerState({ player, state: "stopped" })); dispatch(mixerState.actions.setPlayerState({ player, state: "stopped" }));