wavesurfer.js 7.3.9 → 7.4.0

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 (48) hide show
  1. package/README.md +3 -4
  2. package/dist/event-emitter.d.ts +12 -5
  3. package/dist/event-emitter.js +24 -26
  4. package/dist/plugins/envelope.cjs +1 -1
  5. package/dist/plugins/envelope.esm.js +1 -1
  6. package/dist/plugins/envelope.js +1 -1
  7. package/dist/plugins/envelope.min.js +1 -1
  8. package/dist/plugins/event-emitter.d.ts +12 -5
  9. package/dist/plugins/hover.cjs +1 -1
  10. package/dist/plugins/hover.esm.js +1 -1
  11. package/dist/plugins/hover.js +1 -1
  12. package/dist/plugins/hover.min.js +1 -1
  13. package/dist/plugins/minimap.cjs +1 -1
  14. package/dist/plugins/minimap.esm.js +1 -1
  15. package/dist/plugins/minimap.js +1 -1
  16. package/dist/plugins/minimap.min.js +1 -1
  17. package/dist/plugins/plugins/zoom.d.ts +37 -0
  18. package/dist/plugins/record.cjs +1 -1
  19. package/dist/plugins/record.esm.js +1 -1
  20. package/dist/plugins/record.js +1 -1
  21. package/dist/plugins/record.min.js +1 -1
  22. package/dist/plugins/regions.cjs +1 -1
  23. package/dist/plugins/regions.esm.js +1 -1
  24. package/dist/plugins/regions.js +1 -1
  25. package/dist/plugins/regions.min.js +1 -1
  26. package/dist/plugins/spectrogram.cjs +1 -1
  27. package/dist/plugins/spectrogram.esm.js +1 -1
  28. package/dist/plugins/spectrogram.js +1 -1
  29. package/dist/plugins/spectrogram.min.js +1 -1
  30. package/dist/plugins/timeline.cjs +1 -1
  31. package/dist/plugins/timeline.esm.js +1 -1
  32. package/dist/plugins/timeline.js +1 -1
  33. package/dist/plugins/timeline.min.js +1 -1
  34. package/dist/plugins/wavesurfer.d.ts +4 -0
  35. package/dist/plugins/webaudio.d.ts +49 -0
  36. package/dist/plugins/zoom.cjs +1 -0
  37. package/dist/plugins/zoom.d.ts +37 -0
  38. package/dist/plugins/zoom.esm.js +1 -0
  39. package/dist/plugins/zoom.js +1 -0
  40. package/dist/plugins/zoom.min.js +1 -0
  41. package/dist/wavesurfer.cjs +1 -1
  42. package/dist/wavesurfer.d.ts +4 -0
  43. package/dist/wavesurfer.esm.js +1 -1
  44. package/dist/wavesurfer.js +36 -17
  45. package/dist/wavesurfer.min.js +1 -1
  46. package/dist/webaudio.d.ts +49 -0
  47. package/dist/webaudio.js +150 -0
  48. package/package.json +2 -2
@@ -0,0 +1,150 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import EventEmitter from './event-emitter.js';
11
+ /**
12
+ * A Web Audio buffer player emulating the behavior of an HTML5 Audio element.
13
+ */
14
+ class WebAudioPlayer extends EventEmitter {
15
+ constructor(audioContext = new AudioContext()) {
16
+ super();
17
+ this.bufferNode = null;
18
+ this.autoplay = false;
19
+ this.playStartTime = 0;
20
+ this.playedDuration = 0;
21
+ this._muted = false;
22
+ this.buffer = null;
23
+ this.currentSrc = '';
24
+ this.paused = true;
25
+ this.crossOrigin = null;
26
+ this.audioContext = audioContext;
27
+ this.gainNode = this.audioContext.createGain();
28
+ this.gainNode.connect(this.audioContext.destination);
29
+ }
30
+ load() {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ return;
33
+ });
34
+ }
35
+ get src() {
36
+ return this.currentSrc;
37
+ }
38
+ set src(value) {
39
+ this.currentSrc = value;
40
+ fetch(value)
41
+ .then((response) => response.arrayBuffer())
42
+ .then((arrayBuffer) => this.audioContext.decodeAudioData(arrayBuffer))
43
+ .then((audioBuffer) => {
44
+ this.buffer = audioBuffer;
45
+ this.emit('loadedmetadata');
46
+ this.emit('canplay');
47
+ if (this.autoplay)
48
+ this.play();
49
+ });
50
+ }
51
+ _play() {
52
+ var _a;
53
+ if (!this.paused)
54
+ return;
55
+ this.paused = false;
56
+ (_a = this.bufferNode) === null || _a === void 0 ? void 0 : _a.disconnect();
57
+ this.bufferNode = this.audioContext.createBufferSource();
58
+ this.bufferNode.buffer = this.buffer;
59
+ this.bufferNode.connect(this.gainNode);
60
+ if (this.playedDuration >= this.duration) {
61
+ this.playedDuration = 0;
62
+ }
63
+ this.bufferNode.start(this.audioContext.currentTime, this.playedDuration);
64
+ this.playStartTime = this.audioContext.currentTime;
65
+ this.bufferNode.onended = () => {
66
+ if (this.currentTime >= this.duration) {
67
+ this.pause();
68
+ this.emit('ended');
69
+ }
70
+ };
71
+ }
72
+ _pause() {
73
+ var _a;
74
+ if (this.paused)
75
+ return;
76
+ this.paused = true;
77
+ (_a = this.bufferNode) === null || _a === void 0 ? void 0 : _a.stop();
78
+ this.playedDuration += this.audioContext.currentTime - this.playStartTime;
79
+ }
80
+ play() {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ this._play();
83
+ this.emit('play');
84
+ });
85
+ }
86
+ pause() {
87
+ this._pause();
88
+ this.emit('pause');
89
+ }
90
+ setSinkId(deviceId) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const ac = this.audioContext;
93
+ return ac.setSinkId(deviceId);
94
+ });
95
+ }
96
+ get playbackRate() {
97
+ var _a, _b;
98
+ return (_b = (_a = this.bufferNode) === null || _a === void 0 ? void 0 : _a.playbackRate.value) !== null && _b !== void 0 ? _b : 1;
99
+ }
100
+ set playbackRate(value) {
101
+ if (this.bufferNode) {
102
+ this.bufferNode.playbackRate.value = value;
103
+ }
104
+ }
105
+ get currentTime() {
106
+ return this.paused ? this.playedDuration : this.playedDuration + this.audioContext.currentTime - this.playStartTime;
107
+ }
108
+ set currentTime(value) {
109
+ this.emit('seeking');
110
+ if (this.paused) {
111
+ this.playedDuration = value;
112
+ }
113
+ else {
114
+ this._pause();
115
+ this.playedDuration = value;
116
+ this._play();
117
+ }
118
+ this.emit('timeupdate');
119
+ }
120
+ get duration() {
121
+ var _a;
122
+ return ((_a = this.buffer) === null || _a === void 0 ? void 0 : _a.duration) || 0;
123
+ }
124
+ get volume() {
125
+ return this.gainNode.gain.value;
126
+ }
127
+ set volume(value) {
128
+ this.gainNode.gain.value = value;
129
+ this.emit('volumechange');
130
+ }
131
+ get muted() {
132
+ return this._muted;
133
+ }
134
+ set muted(value) {
135
+ if (this._muted === value)
136
+ return;
137
+ this._muted = value;
138
+ if (this._muted) {
139
+ this.gainNode.disconnect();
140
+ }
141
+ else {
142
+ this.gainNode.connect(this.audioContext.destination);
143
+ }
144
+ }
145
+ /** Get the GainNode used to play the audio. Can be used to attach filters. */
146
+ getGainNode() {
147
+ return this.gainNode;
148
+ }
149
+ }
150
+ export default WebAudioPlayer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wavesurfer.js",
3
- "version": "7.3.9",
3
+ "version": "7.4.0",
4
4
  "license": "BSD-3-Clause",
5
5
  "author": "katspaugh",
6
6
  "description": "Navigable audio waveform player",
@@ -56,7 +56,7 @@
56
56
  "cypress": "cypress open --e2e",
57
57
  "cypress:canary": "cypress open --e2e -b chrome:canary",
58
58
  "test": "cypress run",
59
- "serve": "npx live-server --port=9090 --no-browser",
59
+ "serve": "npx live-server --port=9090 --no-browser --ignore='.*'",
60
60
  "start": "npm run build:dev & npm run serve"
61
61
  },
62
62
  "devDependencies": {