@panelwave/player 1.6.0 → 1.6.1
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.
|
@@ -5456,6 +5456,28 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.14", ngImpo
|
|
|
5456
5456
|
* Manages audio playback with Web Audio API
|
|
5457
5457
|
*/
|
|
5458
5458
|
const ROLES = ['ambient', 'music', 'voiceover', 'sfx'];
|
|
5459
|
+
/**
|
|
5460
|
+
* Whether an audio URL must be loaded with `crossOrigin = 'anonymous'`: an
|
|
5461
|
+
* http(s) file on another origin than the page. Same-origin files, data:/
|
|
5462
|
+
* blob: URLs and `file:` pages (the offline self-hosting package) stay in
|
|
5463
|
+
* no-CORS mode — CORS requests from a file: page fail.
|
|
5464
|
+
*/
|
|
5465
|
+
function needsCorsMode(url, pageHref = typeof location !== 'undefined' ? location.href : '') {
|
|
5466
|
+
try {
|
|
5467
|
+
const target = new URL(url, pageHref || undefined);
|
|
5468
|
+
if (target.protocol !== 'http:' && target.protocol !== 'https:') {
|
|
5469
|
+
return false;
|
|
5470
|
+
}
|
|
5471
|
+
const page = pageHref ? new URL(pageHref) : null;
|
|
5472
|
+
if (page && page.protocol !== 'http:' && page.protocol !== 'https:') {
|
|
5473
|
+
return false;
|
|
5474
|
+
}
|
|
5475
|
+
return !page || target.origin !== page.origin;
|
|
5476
|
+
}
|
|
5477
|
+
catch {
|
|
5478
|
+
return false;
|
|
5479
|
+
}
|
|
5480
|
+
}
|
|
5459
5481
|
/**
|
|
5460
5482
|
* Audio Engine Service
|
|
5461
5483
|
* Provides Web Audio API-based audio playback with multiple buses.
|
|
@@ -5859,8 +5881,15 @@ class AudioEngineService {
|
|
|
5859
5881
|
if (!bus) {
|
|
5860
5882
|
throw new Error(`Invalid role: ${track.role}`);
|
|
5861
5883
|
}
|
|
5862
|
-
// Create audio element
|
|
5863
|
-
|
|
5884
|
+
// Create audio element. A file from another origin (object storage, a
|
|
5885
|
+
// CDN) must be fetched in CORS mode: routed through Web Audio
|
|
5886
|
+
// (createMediaElementSource below), a no-CORS cross-origin element plays
|
|
5887
|
+
// but outputs silence. crossOrigin has to be set before the src.
|
|
5888
|
+
const audio = new Audio();
|
|
5889
|
+
if (needsCorsMode(track.url)) {
|
|
5890
|
+
audio.crossOrigin = 'anonymous';
|
|
5891
|
+
}
|
|
5892
|
+
audio.src = track.url;
|
|
5864
5893
|
audio.loop = track.loop || false;
|
|
5865
5894
|
const rate = typeof track.playbackRate === 'number' && isFinite(track.playbackRate) ? Math.max(0.25, Math.min(4, track.playbackRate)) : 1;
|
|
5866
5895
|
if (rate !== 1) {
|