@@ -42,7 +42,7 @@ export class Waveform {
42
42
protected _waveData : number [ ] ;
43
43
protected _waveLayoutOptions : IWaveLayoutOptions = Waveform . layoutOptions ;
44
44
protected _firstDrawing = true ;
45
- protected _latestRange : number ;
45
+ protected _latestRange : number | null = null ;
46
46
protected _plugins : [ ] = [ ] ;
47
47
protected _waveClickCallback : IWaveClickCallback | null = null ;
48
48
@@ -90,6 +90,10 @@ export class Waveform {
90
90
91
91
public setWaveData ( data : number [ ] ) : void {
92
92
93
+ // reset the _latestRange to allow a new
94
+ // draw even if the range did not change
95
+ this . _latestRange = null ;
96
+
93
97
this . _waveData = data ;
94
98
95
99
}
@@ -165,13 +169,18 @@ export class Waveform {
165
169
*
166
170
* @param range
167
171
*/
168
- public draw ( range ?: number ) : void {
172
+ public draw ( range ?: number , force = false ) : void {
169
173
170
174
// measure fps
171
175
//this.fps();
172
176
173
177
const peaksLength = this . _waveData . length ;
174
178
179
+ if ( peaksLength === 0 ) {
180
+ // nothing to draw
181
+ return ;
182
+ }
183
+
175
184
// the canvas width is the width of all the peaks, plus the width of
176
185
// all the spaces, the amount of spaces is equal to the amount of peaks
177
186
// minus one
@@ -186,7 +195,8 @@ export class Waveform {
186
195
peaksRange = Math . round ( range * peaksPercentage ) ;
187
196
188
197
// if the range did not change since last draw don't redraw
189
- if ( peaksRange === this . _latestRange ) {
198
+ // except if force is true
199
+ if ( peaksRange === this . _latestRange && ! force ) {
190
200
return ;
191
201
}
192
202
0 commit comments