diff --git a/src/mixer/audio.ts b/src/mixer/audio.ts index c8b3418..3e699f4 100644 --- a/src/mixer/audio.ts +++ b/src/mixer/audio.ts @@ -55,6 +55,10 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) { this.wavesurfer.drawBuffer(); } + setCurrentTime(secs: number) { + this.wavesurfer.setCurrentTime(secs); + } + setIntro(duration: number) { if ("intro" in this.wavesurfer.regions.list) { this.wavesurfer.regions.list.intro.end = duration; @@ -149,6 +153,8 @@ class Player extends ((PlayerEmitter as unknown) as { new (): EventEmitter }) { const wavesurfer = WaveSurfer.create({ audioContext: engine.audioContext, container: "#waveform-" + player.toString(), + cursorColor: "#777", + cursorWidth: 3, waveColor: "#CCCCFF", backgroundColor: "#FFFFFF", progressColor: "#9999FF", diff --git a/src/mixer/state.ts b/src/mixer/state.ts index 14c4bc8..686d7e3 100644 --- a/src/mixer/state.ts +++ b/src/mixer/state.ts @@ -450,6 +450,7 @@ export const load = ( } if (state.loadedItem && "cue" in state.loadedItem) { playerInstance.setCue(state.loadedItem.cue); + playerInstance.setCurrentTime(state.loadedItem.cue); } if (state.loadedItem && "outro" in state.loadedItem) { 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) => { - if (typeof audioEngine.players[player] === "undefined") { + + const playerInstance = audioEngine.players[player]; + if (typeof playerInstance === "undefined") { console.log("nothing loaded"); return; } @@ -585,7 +588,21 @@ export const stop = (player: number): AppThunk => (dispatch, getState) => { console.log("not ready"); 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. dispatch(mixerState.actions.setPlayerState({ player, state: "stopped" }));