Let stop button go back to Cue point, and to 0 on second click.
This commit is contained in:
parent
844ad41721
commit
77fb88c913
2 changed files with 25 additions and 2 deletions
|
@ -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",
|
||||
|
|
|
@ -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" }));
|
||||
|
||||
|
|
Loading…
Reference in a new issue