wavesurfer.js 7.7.0 → 7.7.2
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.
- package/README.md +5 -0
- package/dist/plugins/minimap.cjs +1 -1
- package/dist/plugins/minimap.esm.js +1 -1
- package/dist/plugins/minimap.js +1 -1
- package/dist/plugins/minimap.min.js +1 -1
- package/dist/plugins/timeline.cjs +1 -1
- package/dist/plugins/timeline.esm.js +1 -1
- package/dist/plugins/timeline.js +1 -1
- package/dist/plugins/timeline.min.js +1 -1
- package/dist/plugins/webaudio.d.ts +2 -0
- package/dist/renderer.js +12 -3
- package/dist/wavesurfer.cjs +1 -1
- package/dist/wavesurfer.esm.js +1 -1
- package/dist/wavesurfer.min.js +1 -1
- package/dist/webaudio.d.ts +2 -0
- package/dist/webaudio.js +27 -16
- package/package.json +6 -1
package/dist/webaudio.js
CHANGED
|
@@ -19,10 +19,12 @@ class WebAudioPlayer extends EventEmitter {
|
|
|
19
19
|
this.playStartTime = 0;
|
|
20
20
|
this.playedDuration = 0;
|
|
21
21
|
this._muted = false;
|
|
22
|
+
this._playbackRate = 1;
|
|
22
23
|
this.buffer = null;
|
|
23
24
|
this.currentSrc = '';
|
|
24
25
|
this.paused = true;
|
|
25
26
|
this.crossOrigin = null;
|
|
27
|
+
this.seeking = false;
|
|
26
28
|
/** Subscribe to an event. Returns an unsubscribe function. */
|
|
27
29
|
this.addEventListener = this.on;
|
|
28
30
|
/** Unsubscribe from an event */
|
|
@@ -47,7 +49,12 @@ class WebAudioPlayer extends EventEmitter {
|
|
|
47
49
|
return;
|
|
48
50
|
}
|
|
49
51
|
fetch(value)
|
|
50
|
-
.then((response) =>
|
|
52
|
+
.then((response) => {
|
|
53
|
+
if (response.status >= 400) {
|
|
54
|
+
throw new Error(`Failed to fetch ${value}: ${response.status} (${response.statusText})`);
|
|
55
|
+
}
|
|
56
|
+
return response.arrayBuffer();
|
|
57
|
+
})
|
|
51
58
|
.then((arrayBuffer) => {
|
|
52
59
|
if (this.currentSrc !== value)
|
|
53
60
|
return null;
|
|
@@ -71,11 +78,14 @@ class WebAudioPlayer extends EventEmitter {
|
|
|
71
78
|
(_a = this.bufferNode) === null || _a === void 0 ? void 0 : _a.disconnect();
|
|
72
79
|
this.bufferNode = this.audioContext.createBufferSource();
|
|
73
80
|
this.bufferNode.buffer = this.buffer;
|
|
81
|
+
this.bufferNode.playbackRate.value = this._playbackRate;
|
|
74
82
|
this.bufferNode.connect(this.gainNode);
|
|
75
|
-
|
|
83
|
+
let currentPos = this.playedDuration * this._playbackRate;
|
|
84
|
+
if (currentPos >= this.duration) {
|
|
85
|
+
currentPos = 0;
|
|
76
86
|
this.playedDuration = 0;
|
|
77
87
|
}
|
|
78
|
-
this.bufferNode.start(this.audioContext.currentTime,
|
|
88
|
+
this.bufferNode.start(this.audioContext.currentTime, currentPos);
|
|
79
89
|
this.playStartTime = this.audioContext.currentTime;
|
|
80
90
|
this.bufferNode.onended = () => {
|
|
81
91
|
if (this.currentTime >= this.duration) {
|
|
@@ -86,19 +96,21 @@ class WebAudioPlayer extends EventEmitter {
|
|
|
86
96
|
}
|
|
87
97
|
_pause() {
|
|
88
98
|
var _a;
|
|
89
|
-
if (this.paused)
|
|
90
|
-
return;
|
|
91
99
|
this.paused = true;
|
|
92
100
|
(_a = this.bufferNode) === null || _a === void 0 ? void 0 : _a.stop();
|
|
93
101
|
this.playedDuration += this.audioContext.currentTime - this.playStartTime;
|
|
94
102
|
}
|
|
95
103
|
play() {
|
|
96
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
if (!this.paused)
|
|
106
|
+
return;
|
|
97
107
|
this._play();
|
|
98
108
|
this.emit('play');
|
|
99
109
|
});
|
|
100
110
|
}
|
|
101
111
|
pause() {
|
|
112
|
+
if (this.paused)
|
|
113
|
+
return;
|
|
102
114
|
this._pause();
|
|
103
115
|
this.emit('pause');
|
|
104
116
|
}
|
|
@@ -118,27 +130,26 @@ class WebAudioPlayer extends EventEmitter {
|
|
|
118
130
|
});
|
|
119
131
|
}
|
|
120
132
|
get playbackRate() {
|
|
121
|
-
|
|
122
|
-
return (_b = (_a = this.bufferNode) === null || _a === void 0 ? void 0 : _a.playbackRate.value) !== null && _b !== void 0 ? _b : 1;
|
|
133
|
+
return this._playbackRate;
|
|
123
134
|
}
|
|
124
135
|
set playbackRate(value) {
|
|
136
|
+
this._playbackRate = value;
|
|
125
137
|
if (this.bufferNode) {
|
|
126
138
|
this.bufferNode.playbackRate.value = value;
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
141
|
get currentTime() {
|
|
130
|
-
|
|
142
|
+
const time = this.paused
|
|
143
|
+
? this.playedDuration
|
|
144
|
+
: this.playedDuration + (this.audioContext.currentTime - this.playStartTime);
|
|
145
|
+
return time * this._playbackRate;
|
|
131
146
|
}
|
|
132
147
|
set currentTime(value) {
|
|
133
148
|
this.emit('seeking');
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this._pause();
|
|
139
|
-
this.playedDuration = value;
|
|
140
|
-
this._play();
|
|
141
|
-
}
|
|
149
|
+
const wasPlaying = !this.paused;
|
|
150
|
+
wasPlaying && this._pause();
|
|
151
|
+
this.playedDuration = value / this._playbackRate;
|
|
152
|
+
wasPlaying && this._play();
|
|
142
153
|
this.emit('timeupdate');
|
|
143
154
|
}
|
|
144
155
|
get duration() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wavesurfer.js",
|
|
3
|
-
"version": "7.7.
|
|
3
|
+
"version": "7.7.2",
|
|
4
4
|
"license": "BSD-3-Clause",
|
|
5
5
|
"author": "katspaugh",
|
|
6
6
|
"description": "Audio waveform player",
|
|
@@ -44,6 +44,11 @@
|
|
|
44
44
|
},
|
|
45
45
|
"./dist/*": {
|
|
46
46
|
"import": "./dist/*"
|
|
47
|
+
},
|
|
48
|
+
"./dist/plugins/*.esm.js": {
|
|
49
|
+
"import": "./dist/plugins/*.esm.js",
|
|
50
|
+
"types": "./dist/plugins/*.d.ts",
|
|
51
|
+
"require": "./dist/plugins/*.cjs"
|
|
47
52
|
}
|
|
48
53
|
},
|
|
49
54
|
"scripts": {
|