wavesurfer.js 6.6.2 → 6.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +1 -1
  2. package/dist/plugin/wavesurfer.cursor.js +1 -1
  3. package/dist/plugin/wavesurfer.cursor.min.js +1 -1
  4. package/dist/plugin/wavesurfer.elan.js +1 -1
  5. package/dist/plugin/wavesurfer.elan.min.js +1 -1
  6. package/dist/plugin/wavesurfer.markers.js +12 -3
  7. package/dist/plugin/wavesurfer.markers.js.map +1 -1
  8. package/dist/plugin/wavesurfer.markers.min.js +2 -2
  9. package/dist/plugin/wavesurfer.markers.min.js.map +1 -1
  10. package/dist/plugin/wavesurfer.mediasession.js +1 -1
  11. package/dist/plugin/wavesurfer.mediasession.min.js +1 -1
  12. package/dist/plugin/wavesurfer.microphone.js +1 -1
  13. package/dist/plugin/wavesurfer.microphone.min.js +1 -1
  14. package/dist/plugin/wavesurfer.minimap.js +1 -1
  15. package/dist/plugin/wavesurfer.minimap.min.js +1 -1
  16. package/dist/plugin/wavesurfer.playhead.js +1 -1
  17. package/dist/plugin/wavesurfer.playhead.min.js +1 -1
  18. package/dist/plugin/wavesurfer.regions.js +1 -1
  19. package/dist/plugin/wavesurfer.regions.min.js +1 -1
  20. package/dist/plugin/wavesurfer.spectrogram.js +1 -1
  21. package/dist/plugin/wavesurfer.spectrogram.min.js +1 -1
  22. package/dist/plugin/wavesurfer.timeline.js +1 -1
  23. package/dist/plugin/wavesurfer.timeline.min.js +1 -1
  24. package/dist/wavesurfer-html-init.js +1 -1
  25. package/dist/wavesurfer-html-init.min.js +1 -1
  26. package/dist/wavesurfer.js +12 -28
  27. package/dist/wavesurfer.js.map +1 -1
  28. package/dist/wavesurfer.min.js +2 -2
  29. package/dist/wavesurfer.min.js.map +1 -1
  30. package/package.json +1 -1
  31. package/src/plugin/markers/index.js +9 -2
  32. package/src/webaudio.js +9 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wavesurfer.js",
3
- "version": "6.6.2",
3
+ "version": "6.6.3",
4
4
  "description": "Interactive navigable audio visualization using Web Audio and Canvas",
5
5
  "main": "dist/wavesurfer.js",
6
6
  "directories": {
@@ -70,6 +70,9 @@ export default class MarkersPlugin {
70
70
  }
71
71
  return this.markers.add(options);
72
72
  },
73
+ getMarkers() {
74
+ return this.markers;
75
+ },
73
76
  clearMarkers() {
74
77
  this.markers && this.markers.clear();
75
78
  }
@@ -181,9 +184,13 @@ export default class MarkersPlugin {
181
184
  /**
182
185
  * Remove a marker
183
186
  *
184
- * @param {number} index Index of the marker to remove
187
+ * @param {number|Object} indexOrMarker Index of the marker to remove or the marker object itself
185
188
  */
186
- remove(index) {
189
+ remove(indexOrMarker) {
190
+ let index = indexOrMarker;
191
+ if (isNaN(index)) {
192
+ index = this.markers.findIndex(marker => marker === indexOrMarker);
193
+ }
187
194
  let marker = this.markers[index];
188
195
  if (!marker) {
189
196
  return;
package/src/webaudio.js CHANGED
@@ -8,16 +8,12 @@ const FINISHED = 'finished';
8
8
  /**
9
9
  * WebAudio backend
10
10
  *
11
- * @extends {Observer}
11
+ * @extends {util.Observer}
12
12
  */
13
13
  export default class WebAudio extends util.Observer {
14
- /** scriptBufferSize: size of the processing buffer */
15
- static scriptBufferSize = 256;
16
14
  /** audioContext: allows to process audio with WebAudio API */
17
15
  audioContext = null;
18
16
  /** @private */
19
- offlineAudioContext = null;
20
- /** @private */
21
17
  stateBehaviors = {
22
18
  [PLAYING]: {
23
19
  init() {
@@ -33,7 +29,6 @@ export default class WebAudio extends util.Observer {
33
29
  },
34
30
  [PAUSED]: {
35
31
  init() {
36
- this.removeOnAudioProcess();
37
32
  },
38
33
  getPlayedPercents() {
39
34
  const duration = this.getDuration();
@@ -45,7 +40,6 @@ export default class WebAudio extends util.Observer {
45
40
  },
46
41
  [FINISHED]: {
47
42
  init() {
48
- this.removeOnAudioProcess();
49
43
  this.fireEvent('finish');
50
44
  },
51
45
  getPlayedPercents() {
@@ -233,40 +227,29 @@ export default class WebAudio extends util.Observer {
233
227
  createScriptNode() {
234
228
  if (this.params.audioScriptProcessor) {
235
229
  this.scriptNode = this.params.audioScriptProcessor;
236
- } else {
237
- if (this.ac.createScriptProcessor) {
238
- this.scriptNode = this.ac.createScriptProcessor(
239
- WebAudio.scriptBufferSize
240
- );
241
- } else {
242
- this.scriptNode = this.ac.createJavaScriptNode(
243
- WebAudio.scriptBufferSize
244
- );
245
- }
230
+ this.scriptNode.connect(this.ac.destination);
246
231
  }
247
- this.scriptNode.connect(this.ac.destination);
248
232
  }
249
233
 
250
234
  /** @private */
251
235
  addOnAudioProcess() {
252
- this.scriptNode.onaudioprocess = () => {
236
+ const loop = () => {
253
237
  const time = this.getCurrentTime();
254
238
 
255
- if (time >= this.getDuration()) {
239
+ if (time >= this.getDuration() && this.state !== this.states[FINISHED]) {
256
240
  this.setState(FINISHED);
257
241
  this.fireEvent('pause');
258
- } else if (time >= this.scheduledPause) {
242
+ } else if (time >= this.scheduledPause && this.state !== this.states[PAUSED]) {
259
243
  this.pause();
260
244
  } else if (this.state === this.states[PLAYING]) {
261
245
  this.fireEvent('audioprocess', time);
246
+ util.frame(loop)();
262
247
  }
263
248
  };
264
- }
265
249
 
266
- /** @private */
267
- removeOnAudioProcess() {
268
- this.scriptNode.onaudioprocess = null;
250
+ loop();
269
251
  }
252
+
270
253
  /** Create analyser node to perform audio analysis */
271
254
  createAnalyserNode() {
272
255
  this.analyser = this.ac.createAnalyser();
@@ -526,7 +509,7 @@ export default class WebAudio extends util.Observer {
526
509
  this.disconnectFilters();
527
510
  this.disconnectSource();
528
511
  this.gainNode.disconnect();
529
- this.scriptNode.disconnect();
512
+ this.scriptNode && this.scriptNode.disconnect();
530
513
  this.analyser.disconnect();
531
514
 
532
515
  // close the audioContext if closeAudioContext option is set to true