Skip to content

Commit 8c40f57

Browse files
committed
fix: add AudioController's finish method to remove the problem caused by pause after playback
1 parent 11dc8da commit 8c40f57

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/components/IllestWaveform.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const maskWidth = ref<number>(0)
111111
112112
function drawWaveMask(): void | undefined {
113113
if (!audioController._playing) return
114+
114115
requestAnimationFrame(drawWaveMask)
115116
currentTime.value = audioController._currentTime
116117
maskWidth.value =
@@ -127,6 +128,7 @@ function mouseMoveHandler(e: any): void {
127128
128129
function clickHandler(): void {
129130
if (!ready.value || !props.interact) return
131+
130132
maskWidth.value = moveX.value
131133
const pickedTime: number =
132134
(moveX.value / wave._canvas.width) * audioController._audioDuration
@@ -157,13 +159,14 @@ function pause(): void {
157159
}
158160
159161
function finish(): void {
162+
audioController.finish()
163+
emits('onPlay', false)
160164
emits('onFinish', true)
161165
}
162166
163167
function watchIsFinish(): void {
164168
watchEffect(() => {
165-
if (currentTime.value < audioController._audioDuration) return
166-
pause()
169+
if (currentTime.value <= audioController._audioDuration) return
167170
finish()
168171
})
169172
}

src/modules/AudioController.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ export default class WebAudioController extends WebAudio {
4848
}
4949

5050
public pick(pickedTime: number): void {
51-
if (pickedTime <= 0) pickedTime = 0
52-
if (pickedTime >= this._audioDuration) pickedTime = this._audioDuration
5351
this.pickAt = pickedTime
5452
if (!this.playing) return
5553
this.stopSource()
@@ -61,6 +59,11 @@ export default class WebAudioController extends WebAudio {
6159
this.play()
6260
}
6361

62+
public finish(): void {
63+
this.pauseAt = 0
64+
this.stop()
65+
}
66+
6467
private stop(): void {
6568
this.stopSource()
6669
this.initializeState()

0 commit comments

Comments
 (0)