@@ -71,23 +71,22 @@ function lazyLoadHandler() {
7171const waveRef = ref <HTMLCanvasElement | null >(null )
7272const ready = ref <boolean >(false )
7373
74- let webAudioController : AudioController
74+ let audioController : AudioController
7575let wave: Wave
7676
77- // initialize waveform
7877async function init(): Promise <void > {
7978 if (ready .value ) return
8079 emits (' onInit' , true )
81- await initAudio ()
82- await Promise . all ([ initWave ()] )
80+ await initAudioController ()
81+ await initWave ()
8382 ready .value = true
8483 emits (' onReady' , ready .value )
8584}
8685
8786// initialize web audio
88- async function initAudio (): Promise <void > {
89- webAudioController = new AudioController (props )
90- await webAudioController .setupAudio ()
87+ async function initAudioController (): Promise <void > {
88+ audioController = new AudioController (props )
89+ await audioController .setupAudio ()
9190 watchIsFinish ()
9291}
9392
@@ -96,7 +95,7 @@ async function initWave(): Promise<void> {
9695 wave = new Wave (
9796 waveRef .value as HTMLCanvasElement ,
9897 props ,
99- await webAudioController ._filterData
98+ audioController ._filterData
10099 )
101100 wave .setupCanvas ()
102101 watchEffect (() => {
@@ -105,17 +104,17 @@ async function initWave(): Promise<void> {
105104 })
106105}
107106
108- // Waveform handlers
107+ // wave handlers
109108const moveX = ref <number >(0 )
110109const currentTime = ref <number >(0 )
111110const maskWidth = ref <number >(0 )
112111
113112function drawWaveMask(): void | undefined {
114- if (! webAudioController ._playing ) return
113+ if (! audioController ._playing ) return
115114 requestAnimationFrame (drawWaveMask )
116- currentTime .value = webAudioController ._currentTime
115+ currentTime .value = audioController ._currentTime
117116 maskWidth .value =
118- (currentTime .value / webAudioController ._audioDuration ) * wave ._canvas .width
117+ (currentTime .value / audioController ._audioDuration ) * wave ._canvas .width
119118}
120119
121120function mouseMoveHandler(e : any ): void {
@@ -130,30 +129,30 @@ function clickHandler(): void {
130129 if (! ready .value || ! props .interact ) return
131130 maskWidth .value = moveX .value
132131 const pickedTime: number =
133- (moveX .value / wave ._canvas .width ) * webAudioController ._audioDuration
134- webAudioController .pick (pickedTime )
132+ (moveX .value / wave ._canvas .width ) * audioController ._audioDuration
133+ audioController .pick (pickedTime )
135134 currentTime .value = pickedTime
136135 emits (' onClick' , waveformContainer )
137136 emits (' onFinish' , false )
138137}
139138
140- // Audio handlers
139+ // audio handlers
141140function play(): void {
142141 if (! ready .value ) return
143- webAudioController .play ()
142+ audioController .play ()
144143 emits (' onPlay' , true )
145144 drawWaveMask ()
146145}
147146
148147function replay(): void {
149- webAudioController .replay ()
148+ audioController .replay ()
150149 emits (' onFinish' , false )
151150 emits (' onPlay' , true )
152151 drawWaveMask ()
153152}
154153
155154function pause(): void {
156- webAudioController .pause ()
155+ audioController .pause ()
157156 emits (' onPause' , false )
158157}
159158
@@ -163,7 +162,7 @@ function finish(): void {
163162
164163function watchIsFinish(): void {
165164 watchEffect (() => {
166- if (currentTime .value < webAudioController ._audioDuration ) return
165+ if (currentTime .value < audioController ._audioDuration ) return
167166 pause ()
168167 finish ()
169168 })
@@ -174,7 +173,7 @@ function getCurrentTime(): string {
174173}
175174
176175function getDuration(): string {
177- const duration = webAudioController ._audioDuration
176+ const duration = audioController ._audioDuration
178177 return formatSecond (duration )
179178}
180179
0 commit comments