@@ -74,8 +74,6 @@ export type WaveSurferEvents = {
74
74
load : [ url : string ]
75
75
/** When the audio has been decoded */
76
76
decode : [ duration : number ]
77
- /** When the media element has loaded enough to play */
78
- canplay : [ duration : number ]
79
77
/** When the audio is both decoded and can play */
80
78
ready : [ duration : number ]
81
79
/** When a waveform is drawn */
@@ -112,7 +110,6 @@ class WaveSurfer extends Player<WaveSurferEvents> {
112
110
private timer : Timer
113
111
private plugins : GenericPlugin [ ] = [ ]
114
112
private decodedData : AudioBuffer | null = null
115
- private canPlay = false
116
113
protected subscriptions : Array < ( ) => void > = [ ]
117
114
118
115
/** Create a new WaveSurfer instance */
@@ -137,7 +134,6 @@ class WaveSurfer extends Player<WaveSurferEvents> {
137
134
this . initPlayerEvents ( )
138
135
this . initRendererEvents ( )
139
136
this . initTimerEvents ( )
140
- this . initReadyEvent ( )
141
137
this . initPlugins ( )
142
138
143
139
const url = this . options . url || this . options . media ?. currentSrc || this . options . media ?. src
@@ -177,11 +173,6 @@ class WaveSurfer extends Player<WaveSurferEvents> {
177
173
this . emit ( 'finish' )
178
174
} ) ,
179
175
180
- this . onMediaEvent ( 'canplay' , ( ) => {
181
- this . canPlay = true
182
- this . emit ( 'canplay' , this . getDuration ( ) )
183
- } ) ,
184
-
185
176
this . onMediaEvent ( 'seeking' , ( ) => {
186
177
this . emit ( 'seeking' , this . getCurrentTime ( ) )
187
178
} ) ,
@@ -193,7 +184,7 @@ class WaveSurfer extends Player<WaveSurferEvents> {
193
184
// Seek on click
194
185
this . renderer . on ( 'click' , ( relativeX ) => {
195
186
if ( this . options . interact ) {
196
- this . canPlay && this . seekTo ( relativeX )
187
+ this . seekTo ( relativeX )
197
188
this . emit ( 'interaction' )
198
189
this . emit ( 'click' , relativeX )
199
190
}
@@ -219,19 +210,17 @@ class WaveSurfer extends Player<WaveSurferEvents> {
219
210
this . renderer . on ( 'drag' , ( relativeX ) => {
220
211
if ( ! this . options . interact ) return
221
212
222
- if ( this . canPlay ) {
223
- // Update the visual position
224
- this . renderer . renderProgress ( relativeX )
213
+ // Update the visual position
214
+ this . renderer . renderProgress ( relativeX )
225
215
226
- // Set the audio position with a debounce
227
- clearTimeout ( debounce )
228
- debounce = setTimeout (
229
- ( ) => {
230
- this . seekTo ( relativeX )
231
- } ,
232
- this . isPlaying ( ) ? 0 : 200 ,
233
- )
234
- }
216
+ // Set the audio position with a debounce
217
+ clearTimeout ( debounce )
218
+ debounce = setTimeout (
219
+ ( ) => {
220
+ this . seekTo ( relativeX )
221
+ } ,
222
+ this . isPlaying ( ) ? 0 : 200 ,
223
+ )
235
224
236
225
this . emit ( 'interaction' )
237
226
this . emit ( 'drag' , relativeX )
@@ -252,15 +241,6 @@ class WaveSurfer extends Player<WaveSurferEvents> {
252
241
)
253
242
}
254
243
255
- private initReadyEvent ( ) {
256
- const emitReady = ( ) => {
257
- if ( this . decodedData && this . canPlay ) {
258
- this . emit ( 'ready' , this . getDuration ( ) )
259
- }
260
- }
261
- this . subscriptions . push ( this . on ( 'decode' , emitReady ) , this . on ( 'canplay' , emitReady ) )
262
- }
263
-
264
244
private initPlugins ( ) {
265
245
if ( ! this . options . plugins ?. length ) return
266
246
@@ -294,7 +274,6 @@ class WaveSurfer extends Player<WaveSurferEvents> {
294
274
/** Load an audio file by URL, with optional pre-decoded audio data */
295
275
public async load ( url : string , channelData ?: WaveSurferOptions [ 'peaks' ] , duration ?: number ) {
296
276
this . decodedData = null
297
- this . canPlay = false
298
277
299
278
this . emit ( 'load' , url )
300
279
@@ -319,6 +298,7 @@ class WaveSurfer extends Player<WaveSurferEvents> {
319
298
}
320
299
321
300
this . emit ( 'decode' , this . getDuration ( ) )
301
+ this . emit ( 'ready' , this . getDuration ( ) )
322
302
323
303
this . renderer . render ( this . decodedData )
324
304
}
0 commit comments