@arraypress/waveform-player 1.22.0 → 1.24.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.
- package/dist/waveform-player.cjs +20 -1
- package/dist/waveform-player.cjs.map +2 -2
- package/dist/waveform-player.esm.js +2 -2
- package/dist/waveform-player.esm.js.map +2 -2
- package/dist/waveform-player.js +20 -1
- package/dist/waveform-player.min.js +2 -2
- package/dist/waveform-player.min.js.map +2 -2
- package/index.d.ts +16 -0
- package/package.json +1 -1
- package/src/js/core.js +14 -1
- package/src/js/themes.js +9 -0
- package/src/js/utils.js +3 -0
package/index.d.ts
CHANGED
|
@@ -35,6 +35,15 @@ export type AudioMode = 'self' | 'external';
|
|
|
35
35
|
/** Browser preload hint for the underlying `<audio>` element. */
|
|
36
36
|
export type AudioPreload = 'auto' | 'metadata' | 'none';
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* CORS mode for the underlying `<audio>` element. Left unset by default so the
|
|
40
|
+
* player behaves like a plain `<audio>` and never forces a CORS request. Set
|
|
41
|
+
* `'anonymous'` / `'use-credentials'` only if you specifically need it — doing
|
|
42
|
+
* so breaks playback of media hosted on origins that don't send
|
|
43
|
+
* `Access-Control-Allow-Origin` (e.g. default-config S3/CDN).
|
|
44
|
+
*/
|
|
45
|
+
export type AudioCrossOrigin = 'anonymous' | 'use-credentials';
|
|
46
|
+
|
|
38
47
|
/** Vertical alignment of the play button relative to the waveform. */
|
|
39
48
|
export type ButtonAlign = 'auto' | 'top' | 'center' | 'bottom';
|
|
40
49
|
|
|
@@ -83,6 +92,13 @@ export interface WaveformPlayerOptions {
|
|
|
83
92
|
samples?: number;
|
|
84
93
|
/** `<audio>` preload hint. @default 'metadata' */
|
|
85
94
|
preload?: AudioPreload;
|
|
95
|
+
/**
|
|
96
|
+
* `<audio>` CORS mode. Unset by default so the player behaves like a plain
|
|
97
|
+
* `<audio>` and never forces a CORS request (which breaks playback of media
|
|
98
|
+
* on origins without `Access-Control-Allow-Origin`). Set only if you need it.
|
|
99
|
+
* @default null
|
|
100
|
+
*/
|
|
101
|
+
crossOrigin?: AudioCrossOrigin | null;
|
|
86
102
|
/** Whether the player owns its `<audio>` or delegates to an external controller. @default 'self' */
|
|
87
103
|
audioMode?: AudioMode;
|
|
88
104
|
/** Pre-computed peaks (array, .json URL, or JSON string). Skips Web Audio decoding when provided. */
|
package/package.json
CHANGED
package/src/js/core.js
CHANGED
|
@@ -567,7 +567,13 @@ export class WaveformPlayer {
|
|
|
567
567
|
}
|
|
568
568
|
this.audio = new Audio();
|
|
569
569
|
this.audio.preload = this.options.preload || 'metadata';
|
|
570
|
-
|
|
570
|
+
// Only set crossOrigin when explicitly opted in. Setting it forces a
|
|
571
|
+
// CORS request that breaks playback of media on origins without
|
|
572
|
+
// Access-Control-Allow-Origin; the player never needs CORS-clean media
|
|
573
|
+
// for playback (no createMediaElementSource). See issue #18.
|
|
574
|
+
if (this.options.crossOrigin) {
|
|
575
|
+
this.audio.crossOrigin = this.options.crossOrigin;
|
|
576
|
+
}
|
|
571
577
|
}
|
|
572
578
|
|
|
573
579
|
// ============================================
|
|
@@ -1144,6 +1150,7 @@ export class WaveformPlayer {
|
|
|
1144
1150
|
this.setLoading(true);
|
|
1145
1151
|
this.progress = 0;
|
|
1146
1152
|
this.hasError = false;
|
|
1153
|
+
this.container.classList.remove('waveform-is-placeholder');
|
|
1147
1154
|
|
|
1148
1155
|
// In external mode we don't own an <audio> element — skip
|
|
1149
1156
|
// src assignment + metadata-wait, but still generate the
|
|
@@ -1196,6 +1203,7 @@ export class WaveformPlayer {
|
|
|
1196
1203
|
} catch (error) {
|
|
1197
1204
|
console.warn('[WaveformPlayer] Using placeholder waveform:', error);
|
|
1198
1205
|
this.waveformData = generatePlaceholderWaveform(this.options.samples);
|
|
1206
|
+
this.container.classList.add('waveform-is-placeholder');
|
|
1199
1207
|
}
|
|
1200
1208
|
}
|
|
1201
1209
|
|
|
@@ -1283,6 +1291,11 @@ export class WaveformPlayer {
|
|
|
1283
1291
|
this.audio.preload = options.preload;
|
|
1284
1292
|
}
|
|
1285
1293
|
|
|
1294
|
+
// Apply crossOrigin if it was changed for this track
|
|
1295
|
+
if (options.crossOrigin && this.audio) {
|
|
1296
|
+
this.audio.crossOrigin = options.crossOrigin;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1286
1299
|
// Update artist only when explicitly provided. A null artist keeps the
|
|
1287
1300
|
// existing artist, while an empty string removes it.
|
|
1288
1301
|
if (artist !== null) {
|
package/src/js/themes.js
CHANGED
|
@@ -147,6 +147,15 @@ export const DEFAULT_OPTIONS = {
|
|
|
147
147
|
// every-frame scan means a higher value costs no extra extraction time.
|
|
148
148
|
samples: DEFAULT_SAMPLES,
|
|
149
149
|
preload: 'metadata',
|
|
150
|
+
// CORS mode for the underlying <audio> element. Left null by default so the
|
|
151
|
+
// player behaves like a plain <audio> and never forces a CORS request —
|
|
152
|
+
// setting 'anonymous' here would break playback of media hosted on origins
|
|
153
|
+
// that don't send Access-Control-Allow-Origin (default-config S3/CDN). The
|
|
154
|
+
// playback element is never fed to createMediaElementSource, so it never
|
|
155
|
+
// needs CORS-clean media; peak analysis uses a separate fetch() path with
|
|
156
|
+
// its own placeholder fallback. Set 'anonymous' / 'use-credentials' only if
|
|
157
|
+
// you specifically need it. See issue #18.
|
|
158
|
+
crossOrigin: null,
|
|
150
159
|
|
|
151
160
|
// Audio mode — 'self' = player owns the <audio> element (default, current
|
|
152
161
|
// behavior). 'external' = player is a visualization-only surface; no audio
|
package/src/js/utils.js
CHANGED
|
@@ -175,6 +175,9 @@ export function parseDataAttributes(element) {
|
|
|
175
175
|
if (element.dataset.preload) {
|
|
176
176
|
options.preload = element.dataset.preload;
|
|
177
177
|
}
|
|
178
|
+
if (element.dataset.crossOrigin) {
|
|
179
|
+
options.crossOrigin = element.dataset.crossOrigin;
|
|
180
|
+
}
|
|
178
181
|
if (element.dataset.audioMode) options.audioMode = element.dataset.audioMode;
|
|
179
182
|
|
|
180
183
|
// Waveform style attributes. `data-style` is a shorthand alias for
|