From ffbd40b2a8ebdd49b4bc08b8edaf8aee699d12d3 Mon Sep 17 00:00:00 2001 From: mehekj Date: Tue, 9 Nov 2021 15:42:55 -0500 Subject: fixed playback bug and duration --- src/client/views/nodes/AudioBox.tsx | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/client/views/nodes/AudioBox.tsx') diff --git a/src/client/views/nodes/AudioBox.tsx b/src/client/views/nodes/AudioBox.tsx index 62958a80b..6850c2f6c 100644 --- a/src/client/views/nodes/AudioBox.tsx +++ b/src/client/views/nodes/AudioBox.tsx @@ -64,9 +64,12 @@ export class AudioBox extends ViewBoxAnnotatableComponent { - this.setPlayheadTime(this.timeline!.trimStart); + this.Pause(); + if (fullPlay) this.setPlayheadTime(this.timeline!.trimStart); }, (end - start) * 1000); } else { @@ -254,18 +257,20 @@ export class AudioBox extends ViewBoxAnnotatableComponent { - const eleTime = this._ele?.currentTime || 0; - const start = eleTime === this.timeline?.trimEnd ? this.timeline.trimStart : eleTime; - this.playFrom(start, undefined); - e?.stopPropagation?.(); + if (this.timeline && this._ele) { + const eleTime = this._ele.currentTime; + const start = eleTime >= this.timeline.trimEnd || eleTime <= this.timeline.trimStart ? this.timeline.trimStart : eleTime; + this.playFrom(start, this.timeline.trimEnd, true); + e?.stopPropagation?.(); + } } // pause play back @action - Pause = () => { + Pause = (timeoutClear: boolean = false) => { this._ele?.pause(); this.mediaState = media_state.Paused; - clearTimeout(this._play); // stops clip from jumping back to beginning + if (timeoutClear) clearTimeout(this._play); // prevents jump back to beginning when manually paused } // creates a text document for dictation @@ -293,7 +298,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent { e?.addEventListener("timeupdate", this.timecodeChanged); - e?.addEventListener("ended", this.Pause); + e?.addEventListener("ended", () => this.Pause()); this._ele = e; } @@ -354,13 +359,13 @@ export class AudioBox extends ViewBoxAnnotatableComponent { // hides trim controls and displays new clip - this.Pause(); + this.Pause(true); this.setPlayheadTime(Math.max(Math.min(this.timeline?.trimEnd || 0, this._ele!.currentTime), this.timeline?.trimStart || 0)); this.timeline?.StopTrimming(); } startTrim = (scope: TrimScope) => { - this.Pause(); + this.Pause(true); this.timeline?.StartTrimming(scope); } @@ -370,7 +375,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent
+ onPointerDown={this.mediaState === media_state.Paused ? this.Play : (e) => { e.stopPropagation(); this.Pause(true); }}>
@@ -538,7 +543,7 @@ export class AudioBox extends ViewBoxAnnotatableComponent (this._ele?.duration && this._ele?.duration !== Infinity) && - (this.dataDoc[this.fieldKey + "-duration"] = this.rawDuration = this._ele.duration) + (this.dataDoc[this.fieldKey + "-duration"] = this._ele.duration) )} > -- cgit v1.2.3-70-g09d2