@eva/plugin-sound 2.0.0-beta.9 → 2.0.1-beta.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/EVA.plugin.sound.js
CHANGED
|
@@ -4,8 +4,8 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
|
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
5
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
6
6
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
globalThis.EVA = globalThis.EVA || {};
|
|
8
|
+
globalThis.EVA.plugin = globalThis.EVA.plugin || {};
|
|
9
9
|
var _EVA_IIFE_sound = function (exports, eva_js, pixi_js) {
|
|
10
10
|
'use strict';
|
|
11
11
|
function __decorate(decorators, target, key, desc) {
|
|
@@ -1637,6 +1637,11 @@ var _EVA_IIFE_sound = function (exports, eva_js, pixi_js) {
|
|
|
1637
1637
|
};
|
|
1638
1638
|
pixi_js.extensions.add(soundAsset);
|
|
1639
1639
|
const sound = setInstance(new SoundLibrary());
|
|
1640
|
+
sound.disableAutoPause = true;
|
|
1641
|
+
extensions.push('aac');
|
|
1642
|
+
validateFormats({
|
|
1643
|
+
aac: 'audio/aac'
|
|
1644
|
+
});
|
|
1640
1645
|
pixi_js.extensions.add(soundAsset);
|
|
1641
1646
|
let SoundSystem = class SoundSystem extends eva_js.System {
|
|
1642
1647
|
constructor(obj) {
|
|
@@ -1645,6 +1650,9 @@ var _EVA_IIFE_sound = function (exports, eva_js, pixi_js) {
|
|
|
1645
1650
|
this.components = [];
|
|
1646
1651
|
this.audioBufferCache = {};
|
|
1647
1652
|
_extends(this, obj);
|
|
1653
|
+
if (obj === null || obj === void 0 ? void 0 : obj.useLegacy) {
|
|
1654
|
+
sound.useLegacy = true;
|
|
1655
|
+
}
|
|
1648
1656
|
}
|
|
1649
1657
|
resumeAll() {
|
|
1650
1658
|
sound.resumeAll();
|
|
@@ -1735,7 +1743,7 @@ var _EVA_IIFE_sound = function (exports, eva_js, pixi_js) {
|
|
|
1735
1743
|
this.startTime = 0;
|
|
1736
1744
|
}
|
|
1737
1745
|
get systemContext() {
|
|
1738
|
-
return sound.context;
|
|
1746
|
+
return sound.context.audioContext;
|
|
1739
1747
|
}
|
|
1740
1748
|
get playing() {
|
|
1741
1749
|
if (!this.buffer) return false;
|
|
@@ -1812,4 +1820,4 @@ var _EVA_IIFE_sound = function (exports, eva_js, pixi_js) {
|
|
|
1812
1820
|
});
|
|
1813
1821
|
return exports;
|
|
1814
1822
|
}({}, EVA, PIXI);
|
|
1815
|
-
|
|
1823
|
+
globalThis.EVA.plugin.sound = globalThis.EVA.plugin.sound || _EVA_IIFE_sound;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function ownKeys(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,i)}return s}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(s),!0).forEach((function(e){_defineProperty(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):ownKeys(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}function _defineProperty(t,e,s){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:e+""}function _toPrimitive(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)({}).hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},_extends.apply(null,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{};var _EVA_IIFE_sound=function(t,e,s){"use strict";function i(t,e,s,i){return new(s||(s=Promise))((function(o,r){function n(t){try{h(i.next(t))}catch(t){r(t)}}function u(t){try{h(i.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?o(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(n,u)}h((i=i.apply(t,e||[])).next())}))}let o;function r(){return o}class n{static setParamValue(t,e){if(t.setValueAtTime){const s=r().context;t.setValueAtTime(e,s.audioContext.currentTime)}else t.value=e;return e}}class u extends s.EventEmitter{constructor(){super(...arguments),this.speed=1,this.muted=!1,this.volume=1,this.paused=!1}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}get audioContext(){return console.warn("HTML Audio does not support audioContext"),null}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this.paused}destroy(){this.removeAllListeners()}}let h=0;const a=class extends s.EventEmitter{constructor(t){super(),this.id=h++,this.init(t)}set(t,e){if(void 0===this[t])throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"paused":this.paused=e;break;case"loop":this.loop=e;break;case"muted":this.muted=e}return this}get progress(){const{currentTime:t}=this._source;return t/this._duration}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}_onPlay(){this._playing=!0}_onPause(){this._playing=!1}init(t){this._playing=!1,this._duration=t.source.duration;const e=this._source=t.source.cloneNode(!1);e.src=t.parent.url,e.onplay=this._onPlay.bind(this),e.onpause=this._onPause.bind(this),t.context.on("refresh",this.refresh,this),t.context.on("refreshPaused",this.refreshPaused,this),this._media=t}_internalStop(){this._source&&this._playing&&(this._source.onended=null,this._source.pause())}stop(){this._internalStop(),this._source&&this.emit("stop")}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh()}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}refresh(){const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const s=t.volume*(t.muted?0:1),i=e.volume*(e.muted?0:1),o=this._volume*(this._muted?0:1);this._source.volume=o*s*i,this._source.playbackRate=this._speed*t.speed*e.speed}refreshPaused(){const t=this._media.context,e=this._media.parent,s=this._paused||e.paused||t.paused;s!==this._pausedReal&&(this._pausedReal=s,s?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._source.currentTime,end:this._end,volume:this._volume,speed:this._speed,loop:this._loop})),this.emit("pause",s))}play(t){const{start:e,end:i,speed:o,loop:r,volume:n,muted:u}=t;i&&console.assert(i>e,"End time is before start time"),this._speed=o,this._volume=n,this._loop=!!r,this._muted=u,this.refresh(),this.loop&&null!==i&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=e,this._end=i||this._duration,this._start=Math.max(0,this._start-a.PADDING),this._end=Math.min(this._end+a.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=e,this._source.onloadedmetadata=null,this.emit("progress",e/this._duration,this._duration),s.Ticker.shared.add(this._onUpdate,this))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onUpdate(){this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete()}_onComplete(){s.Ticker.shared.remove(this._onUpdate,this),this._internalStop(),this.emit("progress",1,this._duration),this.emit("end",this)}destroy(){s.Ticker.shared.remove(this._onUpdate,this),this.removeAllListeners();const t=this._source;t&&(t.onended=null,t.onplay=null,t.onpause=null,this._internalStop()),this._source=null,this._speed=1,this._volume=1,this._loop=!1,this._end=null,this._start=0,this._duration=0,this._playing=!1,this._pausedReal=!1,this._paused=!1,this._muted=!1,this._media&&(this._media.context.off("refresh",this.refresh,this),this._media.context.off("refreshPaused",this.refreshPaused,this),this._media=null)}toString(){return`[HTMLAudioInstance id=${this.id}]`}};let l=a;l.PADDING=.1;class d extends s.EventEmitter{init(t){this.parent=t,this._source=t.options.source||new Audio,t.url&&(this._source.src=t.url)}create(){return new l(this)}get isPlayable(){return!!this._source&&4===this._source.readyState}get duration(){return this._source.duration}get context(){return this.parent.context}get filters(){return null}set filters(t){console.warn("HTML Audio does not support filters")}destroy(){this.removeAllListeners(),this.parent=null,this._source&&(this._source.src="",this._source.load(),this._source=null)}get source(){return this._source}load(t){const e=this._source,s=this.parent;if(4===e.readyState){s.isLoaded=!0;const e=s.autoPlayStart();return void(t&&setTimeout((()=>{t(null,s,e)}),0))}if(!s.url)return void t(new Error("sound.url or sound.source must be set"));e.src=s.url;const i=()=>{n(),s.isLoaded=!0;const e=s.autoPlayStart();t&&t(null,s,e)},o=()=>{n(),t&&t(new Error("Sound loading has been aborted"))},r=()=>{n();const s=`Failed to load audio element (code: ${e.error.code})`;t?t(new Error(s)):console.error(s)},n=()=>{e.removeEventListener("canplaythrough",i),e.removeEventListener("load",i),e.removeEventListener("abort",o),e.removeEventListener("error",r)};e.addEventListener("canplaythrough",i,!1),e.addEventListener("load",i,!1),e.addEventListener("abort",o,!1),e.addEventListener("error",r,!1),e.load()}}class c{constructor(t,e){this.parent=t,_extends(this,e),this.duration=this.end-this.start,console.assert(this.duration>0,"End time must be after start time")}play(t){return this.parent.play({complete:t,speed:this.speed||this.parent.speed,end:this.end,start:this.start,loop:this.loop})}destroy(){this.parent=null}}const p=["ogg","oga","opus","m4a","mp3","mpeg","wav","aiff","wma","mid","caf"],_=["audio/mpeg","audio/ogg"],f={};!function(t){const e=_objectSpread({m4a:"audio/mp4",oga:"audio/ogg",opus:'audio/ogg; codecs="opus"',caf:'audio/x-caf; codecs="opus"'},t||{}),s=document.createElement("audio"),i={},o=/^no$/;p.forEach((t=>{const r=s.canPlayType(`audio/${t}`).replace(o,""),n=e[t]?s.canPlayType(e[t]).replace(o,""):"";i[t]=!!r||!!n})),_extends(f,i)}();let m=0;class g extends s.EventEmitter{constructor(t){super(),this.id=m++,this._media=null,this._paused=!1,this._muted=!1,this._elapsed=0,this.init(t)}set(t,e){if(void 0===this[t])throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"muted":this.muted=e;break;case"loop":this.loop=e;break;case"paused":this.paused=e}return this}stop(){this._source&&(this._internalStop(),this.emit("stop"))}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh(),this._update(!0)}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get filters(){return this._filters}set filters(t){var e;this._filters&&(null===(e=this._filters)||void 0===e||e.filter((t=>t)).forEach((t=>t.disconnect())),this._filters=null,this._source.connect(this._gain));this._filters=null!=t&&t.length?t.slice(0):null,this.refresh()}refresh(){if(!this._source)return;const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const s=t.volume*(t.muted?0:1),i=e.volume*(e.muted?0:1),o=this._volume*(this._muted?0:1);n.setParamValue(this._gain.gain,o*i*s),n.setParamValue(this._source.playbackRate,this._speed*e.speed*t.speed),this.applyFilters()}applyFilters(){var t;if(null!==(t=this._filters)&&void 0!==t&&t.length){this._source.disconnect();let t=this._source;this._filters.forEach((e=>{t.connect(e.destination),t=e})),t.connect(this._gain)}}refreshPaused(){const t=this._media.context,e=this._media.parent,s=this._paused||e.paused||t.paused;s!==this._pausedReal&&(this._pausedReal=s,s?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._elapsed%this._duration,end:this._end,speed:this._speed,loop:this._loop,volume:this._volume})),this.emit("pause",s))}play(t){const{start:e,end:s,speed:i,loop:o,volume:r,muted:n,filters:u}=t;s&&console.assert(s>e,"End time is before start time"),this._paused=!1;const{source:h,gain:a}=this._media.nodes.cloneBufferSource();this._source=h,this._gain=a,this._speed=i,this._volume=r,this._loop=!!o,this._muted=n,this._filters=u,this.refresh();const l=this._source.buffer.duration;this._duration=l,this._end=s,this._lastUpdate=this._now(),this._elapsed=e,this._source.onended=this._onComplete.bind(this),this._loop?(this._source.loopEnd=s,this._source.loopStart=e,this._source.start(0,e)):s?this._source.start(0,e,s-e):this._source.start(0,e),this.emit("start"),this._update(!0),this.enableTicker(!0)}enableTicker(t){s.Ticker.shared.remove(this._updateListener,this),t&&s.Ticker.shared.add(this._updateListener,this)}get progress(){return this._progress}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}destroy(){var t;this.removeAllListeners(),this._internalStop(),this._gain&&(this._gain.disconnect(),this._gain=null),this._media&&(this._media.context.events.off("refresh",this.refresh,this),this._media.context.events.off("refreshPaused",this.refreshPaused,this),this._media=null),null===(t=this._filters)||void 0===t||t.forEach((t=>t.disconnect())),this._filters=null,this._end=null,this._speed=1,this._volume=1,this._loop=!1,this._elapsed=0,this._duration=0,this._paused=!1,this._muted=!1,this._pausedReal=!1}toString(){return`[WebAudioInstance id=${this.id}]`}_now(){return this._media.context.audioContext.currentTime}_updateListener(){this._update()}_update(t=!1){if(this._source){const e=this._now(),s=e-this._lastUpdate;if(s>0||t){const t=this._source.playbackRate.value;this._elapsed+=s*t,this._lastUpdate=e;const i=this._duration;let o;if(this._source.loopStart){const t=this._source.loopEnd-this._source.loopStart;o=(this._source.loopStart+this._elapsed%t)/i}else o=this._elapsed%i/i;this._progress=o,this.emit("progress",this._progress,i)}}}init(t){this._media=t,t.context.events.on("refresh",this.refresh,this),t.context.events.on("refreshPaused",this.refreshPaused,this)}_internalStop(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.stop(0),this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null}}_onComplete(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}}this._source=null,this._progress=1,this.emit("progress",1,this._duration),this.emit("end",this)}}class y{constructor(t,e){this._output=e,this._input=t}get destination(){return this._input}get filters(){return this._filters}set filters(t){if(this._filters&&(this._filters.forEach((t=>{t&&t.disconnect()})),this._filters=null,this._input.connect(this._output)),t&&t.length){this._filters=t.slice(0),this._input.disconnect();let e=null;t.forEach((t=>{null===e?this._input.connect(t.destination):e.connect(t.destination),e=t})),e.connect(this._output)}}destroy(){this.filters=null,this._input=null,this._output=null}}const v=class extends y{constructor(t){const e=t.audioContext,s=e.createBufferSource(),i=e.createGain(),o=e.createAnalyser();s.connect(o),o.connect(i),i.connect(t.destination),super(o,i),this.context=t,this.bufferSource=s,this.gain=i,this.analyser=o}get script(){return this._script||(this._script=this.context.audioContext.createScriptProcessor(v.BUFFER_SIZE),this._script.connect(this.context.destination)),this._script}destroy(){super.destroy(),this.bufferSource.disconnect(),this._script&&this._script.disconnect(),this.gain.disconnect(),this.analyser.disconnect(),this.bufferSource=null,this._script=null,this.gain=null,this.analyser=null,this.context=null}cloneBufferSource(){const t=this.bufferSource,e=this.context.audioContext.createBufferSource();e.buffer=t.buffer,n.setParamValue(e.playbackRate,t.playbackRate.value),e.loop=t.loop;const s=this.context.audioContext.createGain();return e.connect(s),s.connect(this.destination),{source:e,gain:s}}get bufferSize(){return this.script.bufferSize}};let b=v;b.BUFFER_SIZE=0;class x{init(t){this.parent=t,this._nodes=new b(this.context),this._source=this._nodes.bufferSource,this.source=t.options.source}destroy(){this.parent=null,this._nodes.destroy(),this._nodes=null;try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null,this.source=null}create(){return new g(this)}get context(){return this.parent.context}get isPlayable(){return!!this._source&&!!this._source.buffer}get filters(){return this._nodes.filters}set filters(t){this._nodes.filters=t}get duration(){return console.assert(this.isPlayable,"Sound not yet playable, no duration"),this._source.buffer.duration}get buffer(){return this._source.buffer}set buffer(t){this._source.buffer=t}get nodes(){return this._nodes}load(t){this.source?this._decode(this.source,t):this.parent.url?this._loadUrl(t):t?t(new Error("sound.url or sound.source must be set")):console.error("sound.url or sound.source must be set")}async _loadUrl(t){const e=this.parent.url,i=await s.DOMAdapter.get().fetch(e);this._decode(await i.arrayBuffer(),t)}_decode(t,e){const s=(t,s)=>{if(t)e&&e(t);else{this.parent.isLoaded=!0,this.buffer=s;const t=this.parent.autoPlayStart();e&&e(null,this.parent,t)}};if(t instanceof AudioBuffer)s(null,t);else{this.parent.context.decode(t,s)}}}const P=class{static from(t){let e={};"string"==typeof t?e.url=t:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?e.source=t:Array.isArray(t)?e.url=t:e=t,e=_objectSpread({autoPlay:!1,singleInstance:!1,url:null,source:null,preload:!1,volume:1,speed:1,complete:null,loaded:null,loop:!1},e),Object.freeze(e);const s=r().useLegacy?new d:new x;return new P(s,e)}constructor(t,e){this.media=t,this.options=e,this._instances=[],this._sprites={},this.media.init(this);const s=e.complete;this._autoPlayOptions=s?{complete:s}:null,this.isLoaded=!1,this._preloadQueue=null,this.isPlaying=!1,this.autoPlay=e.autoPlay,this.singleInstance=e.singleInstance,this.preload=e.preload||this.autoPlay,this.url=Array.isArray(e.url)?this.preferUrl(e.url):e.url,this.speed=e.speed,this.volume=e.volume,this.loop=e.loop,e.sprites&&this.addSprites(e.sprites),this.preload&&this._preload(e.loaded)}preferUrl(t){const[e]=t.map((t=>({url:t,ext:s.path.extname(t).slice(1)}))).filter((({ext:t})=>f[t])).sort(((t,e)=>p.indexOf(t.ext)-p.indexOf(e.ext)));if(!e)throw new Error("No supported file type found");return e.url}get context(){return r().context}pause(){return this.isPlaying=!1,this.paused=!0,this}resume(){return this.isPlaying=this._instances.length>0,this.paused=!1,this}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh()}get filters(){return this.media.filters}set filters(t){this.media.filters=t}addSprites(t,e){if("object"==typeof t){const e={};for(const s in t)e[s]=this.addSprites(s,t[s]);return e}console.assert(!this._sprites[t],`Alias ${t} is already taken`);const s=new c(this,e);return this._sprites[t]=s,s}destroy(){this._removeInstances(),this.removeSprites(),this.media.destroy(),this.media=null,this._sprites=null,this._instances=null}removeSprites(t){if(t){const e=this._sprites[t];void 0!==e&&(e.destroy(),delete this._sprites[t])}else for(const t in this._sprites)this.removeSprites(t);return this}get isPlayable(){return this.isLoaded&&this.media&&this.media.isPlayable}stop(){if(!this.isPlayable)return this.autoPlay=!1,this._autoPlayOptions=null,this;this.isPlaying=!1;for(let t=this._instances.length-1;t>=0;t--)this._instances[t].stop();return this}play(t,e){let s;if("string"==typeof t){s={sprite:t,loop:this.loop,complete:e}}else"function"==typeof t?(s={},s.complete=t):s=t;if(s=_objectSpread({complete:null,loaded:null,sprite:null,end:null,start:0,volume:1,speed:1,muted:!1,loop:!1},s||{}),s.sprite){const t=s.sprite;console.assert(!!this._sprites[t],`Alias ${t} is not available`);const e=this._sprites[t];s.start=e.start+(s.start||0),s.end=e.end,s.speed=e.speed||1,s.loop=e.loop||s.loop,delete s.sprite}if(s.offset&&(s.start=s.offset),!this.isLoaded)return this._preloadQueue?new Promise((t=>{this._preloadQueue.push((()=>{t(this.play(s))}))})):(this._preloadQueue=[],this.autoPlay=!0,this._autoPlayOptions=s,new Promise(((t,e)=>{this._preload(((i,o,r)=>{this._preloadQueue.forEach((t=>t())),this._preloadQueue=null,i?e(i):(s.loaded&&s.loaded(i,o,r),t(r))}))})));(this.singleInstance||s.singleInstance)&&this._removeInstances();const i=this._createInstance();return this._instances.push(i),this.isPlaying=!0,i.once("end",(()=>{s.complete&&s.complete(this),this._onComplete(i)})),i.once("stop",(()=>{this._onComplete(i)})),i.play(s),i}refresh(){const t=this._instances.length;for(let e=0;e<t;e++)this._instances[e].refresh()}refreshPaused(){const t=this._instances.length;for(let e=0;e<t;e++)this._instances[e].refreshPaused()}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}_preload(t){this.media.load(t)}get instances(){return this._instances}get sprites(){return this._sprites}get duration(){return this.media.duration}autoPlayStart(){let t;return this.autoPlay&&(t=this.play(this._autoPlayOptions)),t}_removeInstances(){for(let t=this._instances.length-1;t>=0;t--)this._poolInstance(this._instances[t]);this._instances.length=0}_onComplete(t){if(this._instances){const e=this._instances.indexOf(t);e>-1&&this._instances.splice(e,1),this.isPlaying=this._instances.length>0}this._poolInstance(t)}_createInstance(){if(P._pool.length>0){const t=P._pool.pop();return t.init(this.media),t}return this.media.create()}_poolInstance(t){t.destroy(),P._pool.indexOf(t)<0&&P._pool.push(t)}};let A=P;A._pool=[];class w extends y{constructor(){const t=window,e=new w.AudioContext,i=e.createDynamicsCompressor(),o=e.createAnalyser();o.connect(i),i.connect(e.destination),super(o,i),this.autoPause=!0,this._ctx=e,this._offlineCtx=new w.OfflineAudioContext(1,2,t.OfflineAudioContext?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),this.compressor=i,this.analyser=o,this.events=new s.EventEmitter,this.volume=1,this.speed=1,this.muted=!1,this.paused=!1,this._locked="suspended"===e.state&&("ontouchstart"in globalThis||"onclick"in globalThis),this._locked&&(this._unlock(),this._unlock=this._unlock.bind(this),document.addEventListener("mousedown",this._unlock,!0),document.addEventListener("touchstart",this._unlock,!0),document.addEventListener("touchend",this._unlock,!0)),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onBlur.bind(this),globalThis.addEventListener("focus",this.onFocus),globalThis.addEventListener("blur",this.onBlur)}onFocus(){if(!this.autoPause)return;const t=this._ctx.state;"suspended"!==t&&"interrupted"!==t&&this._locked||(this.paused=this._pausedOnBlur,this.refreshPaused())}onBlur(){this.autoPause&&(this._locked||(this._pausedOnBlur=this._paused,this.paused=!0,this.refreshPaused()))}_unlock(){this._locked&&(this.playEmptySound(),"running"===this._ctx.state&&(document.removeEventListener("mousedown",this._unlock,!0),document.removeEventListener("touchend",this._unlock,!0),document.removeEventListener("touchstart",this._unlock,!0),this._locked=!1))}playEmptySound(){const t=this._ctx.createBufferSource();t.buffer=this._ctx.createBuffer(1,1,22050),t.connect(this._ctx.destination),t.start(0,0,0),"suspended"===t.context.state&&t.context.resume()}static get AudioContext(){const t=window;return t.AudioContext||t.webkitAudioContext||null}static get OfflineAudioContext(){const t=window;return t.OfflineAudioContext||t.webkitOfflineAudioContext||null}destroy(){super.destroy();const t=this._ctx;void 0!==t.close&&t.close(),globalThis.removeEventListener("focus",this.onFocus),globalThis.removeEventListener("blur",this.onBlur),this.events.removeAllListeners(),this.analyser.disconnect(),this.compressor.disconnect(),this.analyser=null,this.compressor=null,this.events=null,this._offlineCtx=null,this._ctx=null}get audioContext(){return this._ctx}get offlineContext(){return this._offlineCtx}set paused(t){t&&"running"===this._ctx.state?this._ctx.suspend():t||"suspended"!==this._ctx.state||this._ctx.resume(),this._paused=t}get paused(){return this._paused}refresh(){this.events.emit("refresh")}refreshPaused(){this.events.emit("refreshPaused")}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this._paused}decode(t,e){const s=t=>{e(new Error((null==t?void 0:t.message)||"Unable to decode file"))},i=this._offlineCtx.decodeAudioData(t,(t=>{e(null,t)}),s);i&&i.catch(s)}}const E=t=>{var e;const i=t.src;let o=null==t||null===(e=t.alias)||void 0===e?void 0:e[0];return o&&t.src!==o||(o=s.path.basename(i,s.path.extname(i))),o},S={extension:s.ExtensionType.Asset,detection:{test:async()=>!0,add:async t=>[...t,...p.filter((t=>f[t]))],remove:async t=>t.filter((e=>t.includes(e)))},loader:{name:"sound",extension:{type:[s.ExtensionType.LoadParser],priority:s.LoaderParserPriority.High},test(t){const e=s.path.extname(t).slice(1);return!!f[e]||_.some((e=>t.startsWith(`data:${e}`)))},async load(t,e){const s=await new Promise(((s,i)=>A.from(_objectSpread(_objectSpread({},e.data),{},{url:t,preload:!0,loaded(t,o){var r,n;t?i(t):s(o),null===(r=e.data)||void 0===r||null===(n=r.loaded)||void 0===n||n.call(r,t,o)}}))));return r().add(E(e),s),s},async unload(t,e){r().remove(E(e))}}};s.extensions.add(S);const C=function(t){return o=t,t}(new class{constructor(){this.init()}init(){return this.supported&&(this._webAudioContext=new w),this._htmlAudioContext=new u,this._sounds={},this.useLegacy=!this.supported,this}get context(){return this._context}get filtersAll(){return this.useLegacy?[]:this._context.filters}set filtersAll(t){this.useLegacy||(this._context.filters=t)}get supported(){return null!==w.AudioContext}add(t,e){if("object"==typeof t){const s={};for(const i in t){const o=this._getOptions(t[i],e);s[i]=this.add(i,o)}return s}if(console.assert(!this._sounds[t],`Sound with alias ${t} already exists.`),e instanceof A)return this._sounds[t]=e,e;const s=this._getOptions(e),i=A.from(s);return this._sounds[t]=i,i}_getOptions(t,e){let s;return s="string"==typeof t||Array.isArray(t)?{url:t}:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?{source:t}:t,s=_objectSpread(_objectSpread({},s),e||{}),s}get useLegacy(){return this._useLegacy}set useLegacy(t){this._useLegacy=t,this._context=!t&&this.supported?this._webAudioContext:this._htmlAudioContext}get disableAutoPause(){return!this._webAudioContext.autoPause}set disableAutoPause(t){this._webAudioContext.autoPause=!t}remove(t){return this.exists(t,!0),this._sounds[t].destroy(),delete this._sounds[t],this}get volumeAll(){return this._context.volume}set volumeAll(t){this._context.volume=t,this._context.refresh()}get speedAll(){return this._context.speed}set speedAll(t){this._context.speed=t,this._context.refresh()}togglePauseAll(){return this._context.togglePause()}pauseAll(){return this._context.paused=!0,this._context.refreshPaused(),this}resumeAll(){return this._context.paused=!1,this._context.refreshPaused(),this}toggleMuteAll(){return this._context.toggleMute()}muteAll(){return this._context.muted=!0,this._context.refresh(),this}unmuteAll(){return this._context.muted=!1,this._context.refresh(),this}removeAll(){for(const t in this._sounds)this._sounds[t].destroy(),delete this._sounds[t];return this}stopAll(){for(const t in this._sounds)this._sounds[t].stop();return this}exists(t,e=!1){const s=!!this._sounds[t];return e&&console.assert(s,`No sound matching alias '${t}'.`),s}isPlaying(){for(const t in this._sounds)if(this._sounds[t].isPlaying)return!0;return!1}find(t){return this.exists(t,!0),this._sounds[t]}play(t,e){return this.find(t).play(e)}stop(t){return this.find(t).stop()}pause(t){return this.find(t).pause()}resume(t){return this.find(t).resume()}volume(t,e){const s=this.find(t);return void 0!==e&&(s.volume=e),s.volume}speed(t,e){const s=this.find(t);return void 0!==e&&(s.speed=e),s.speed}duration(t){return this.find(t).duration}close(){return this.removeAll(),this._sounds=null,this._webAudioContext&&(this._webAudioContext.destroy(),this._webAudioContext=null),this._htmlAudioContext&&(this._htmlAudioContext.destroy(),this._htmlAudioContext=null),this._context=null,this}});s.extensions.add(S);let L=class extends e.System{constructor(t){super(),this.autoPauseAndStart=!0,this.components=[],this.audioBufferCache={},_extends(this,t)}resumeAll(){C.resumeAll()}pauseAll(){C.pauseAll()}stopAll(){C.stopAll()}update(){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}onResume(){this.autoPauseAndStart&&this.resumeAll()}onPause(){this.autoPauseAndStart&&this.pauseAll()}onDestroy(){this.components.forEach((t=>{t.onDestroy()})),this.components=[],C.removeAll()}componentChanged(t){return i(this,void 0,void 0,(function*(){"Sound"===t.componentName&&t.type===e.OBSERVER_TYPE.ADD&&this.add(t)}))}add(t){var s,o;return i(this,void 0,void 0,(function*(){const i=t.component;this.components.push(i);try{const{config:t}=i;i.state="loading";const r=yield e.resource.getResource(t.resource);!this.audioBufferCache[r.name]&&(null===(s=null==r?void 0:r.data)||void 0===s?void 0:s.audio)&&(this.audioBufferCache[r.name]=null===(o=null==r?void 0:r.data)||void 0===o?void 0:o.audio),this.audioBufferCache[r.name]&&i.onload(this.audioBufferCache[r.name])}catch(t){this.onError&&this.onError(t)}}))}};L.systemName="SoundSystem",L=function(t,e,s,i){var o,r=arguments.length,n=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,s,i);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(n=(r<3?o(n):r>3?o(e,s,n):o(e,s))||n);return r>3&&n&&Object.defineProperty(e,s,n),n}([e.decorators.componentObserver({Sound:[]})],L);var O=L;class k extends e.Component{constructor(){super(...arguments),this.state="unloaded",this.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0,speed:1},this.actionQueue=[],this.startTime=0}get systemContext(){return C.context}get playing(){return!!this.buffer&&this.buffer.isPlaying}get muted(){var t;return(null===(t=this.buffer)||void 0===t?void 0:t.muted)||!1}set muted(t){this.buffer&&(this.buffer.muted=t)}get volume(){var t;return(null===(t=this.buffer)||void 0===t?void 0:t.volume)||0}set volume(t){this.buffer&&(this.buffer.volume=t)}init(t){t&&(_extends(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))}play(){"loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.buffer&&(this.startTime=this.systemContext.currentTime,this.buffer.play())}resume(){this.buffer&&this.buffer.resume()}pause(){this.buffer&&this.buffer.pause()}stop(){this.buffer&&this.buffer.stop()}onload(t){this.state="loaded",this.buffer=t,this.buffer.muted=this.config.muted,this.buffer.volume=this.config.volume,this.buffer.loop=this.config.loop,this.buffer.speed=this.config.speed,this.actionQueue.forEach((t=>t())),this.actionQueue.length=0}onDestroy(){this.actionQueue.length=0,this.startTime=0,this.buffer&&(this.buffer.destroy(),this.buffer=null)}}k.componentName="Sound";var T=k;return t.Sound=T,t.SoundSystem=O,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,PIXI);window.EVA.plugin.sound=window.EVA.plugin.sound||_EVA_IIFE_sound;
|
|
1
|
+
function ownKeys(t,e){var s=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),s.push.apply(s,i)}return s}function _objectSpread(t){for(var e=1;e<arguments.length;e++){var s=null!=arguments[e]?arguments[e]:{};e%2?ownKeys(Object(s),!0).forEach((function(e){_defineProperty(t,e,s[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(s)):ownKeys(Object(s)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(s,e))}))}return t}function _defineProperty(t,e,s){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"==typeof e?e:e+""}function _toPrimitive(t,e){if("object"!=typeof t||!t)return t;var s=t[Symbol.toPrimitive];if(void 0!==s){var i=s.call(t,e||"default");if("object"!=typeof i)return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}function _extends(){return _extends=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var i in s)({}).hasOwnProperty.call(s,i)&&(t[i]=s[i])}return t},_extends.apply(null,arguments)}globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_sound=function(t,e,s){"use strict";function i(t,e,s,i){return new(s||(s=Promise))((function(o,r){function n(t){try{h(i.next(t))}catch(t){r(t)}}function u(t){try{h(i.throw(t))}catch(t){r(t)}}function h(t){var e;t.done?o(t.value):(e=t.value,e instanceof s?e:new s((function(t){t(e)}))).then(n,u)}h((i=i.apply(t,e||[])).next())}))}let o;function r(){return o}class n{static setParamValue(t,e){if(t.setValueAtTime){const s=r().context;t.setValueAtTime(e,s.audioContext.currentTime)}else t.value=e;return e}}class u extends s.EventEmitter{constructor(){super(...arguments),this.speed=1,this.muted=!1,this.volume=1,this.paused=!1}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}get audioContext(){return console.warn("HTML Audio does not support audioContext"),null}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this.paused}destroy(){this.removeAllListeners()}}let h=0;const a=class extends s.EventEmitter{constructor(t){super(),this.id=h++,this.init(t)}set(t,e){if(void 0===this[t])throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"paused":this.paused=e;break;case"loop":this.loop=e;break;case"muted":this.muted=e}return this}get progress(){const{currentTime:t}=this._source;return t/this._duration}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}_onPlay(){this._playing=!0}_onPause(){this._playing=!1}init(t){this._playing=!1,this._duration=t.source.duration;const e=this._source=t.source.cloneNode(!1);e.src=t.parent.url,e.onplay=this._onPlay.bind(this),e.onpause=this._onPause.bind(this),t.context.on("refresh",this.refresh,this),t.context.on("refreshPaused",this.refreshPaused,this),this._media=t}_internalStop(){this._source&&this._playing&&(this._source.onended=null,this._source.pause())}stop(){this._internalStop(),this._source&&this.emit("stop")}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh()}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get filters(){return console.warn("HTML Audio does not support filters"),null}set filters(t){console.warn("HTML Audio does not support filters")}refresh(){const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const s=t.volume*(t.muted?0:1),i=e.volume*(e.muted?0:1),o=this._volume*(this._muted?0:1);this._source.volume=o*s*i,this._source.playbackRate=this._speed*t.speed*e.speed}refreshPaused(){const t=this._media.context,e=this._media.parent,s=this._paused||e.paused||t.paused;s!==this._pausedReal&&(this._pausedReal=s,s?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._source.currentTime,end:this._end,volume:this._volume,speed:this._speed,loop:this._loop})),this.emit("pause",s))}play(t){const{start:e,end:i,speed:o,loop:r,volume:n,muted:u}=t;i&&console.assert(i>e,"End time is before start time"),this._speed=o,this._volume=n,this._loop=!!r,this._muted=u,this.refresh(),this.loop&&null!==i&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=e,this._end=i||this._duration,this._start=Math.max(0,this._start-a.PADDING),this._end=Math.min(this._end+a.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=e,this._source.onloadedmetadata=null,this.emit("progress",e/this._duration,this._duration),s.Ticker.shared.add(this._onUpdate,this))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onUpdate(){this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete()}_onComplete(){s.Ticker.shared.remove(this._onUpdate,this),this._internalStop(),this.emit("progress",1,this._duration),this.emit("end",this)}destroy(){s.Ticker.shared.remove(this._onUpdate,this),this.removeAllListeners();const t=this._source;t&&(t.onended=null,t.onplay=null,t.onpause=null,this._internalStop()),this._source=null,this._speed=1,this._volume=1,this._loop=!1,this._end=null,this._start=0,this._duration=0,this._playing=!1,this._pausedReal=!1,this._paused=!1,this._muted=!1,this._media&&(this._media.context.off("refresh",this.refresh,this),this._media.context.off("refreshPaused",this.refreshPaused,this),this._media=null)}toString(){return`[HTMLAudioInstance id=${this.id}]`}};let l=a;l.PADDING=.1;class d extends s.EventEmitter{init(t){this.parent=t,this._source=t.options.source||new Audio,t.url&&(this._source.src=t.url)}create(){return new l(this)}get isPlayable(){return!!this._source&&4===this._source.readyState}get duration(){return this._source.duration}get context(){return this.parent.context}get filters(){return null}set filters(t){console.warn("HTML Audio does not support filters")}destroy(){this.removeAllListeners(),this.parent=null,this._source&&(this._source.src="",this._source.load(),this._source=null)}get source(){return this._source}load(t){const e=this._source,s=this.parent;if(4===e.readyState){s.isLoaded=!0;const e=s.autoPlayStart();return void(t&&setTimeout((()=>{t(null,s,e)}),0))}if(!s.url)return void t(new Error("sound.url or sound.source must be set"));e.src=s.url;const i=()=>{n(),s.isLoaded=!0;const e=s.autoPlayStart();t&&t(null,s,e)},o=()=>{n(),t&&t(new Error("Sound loading has been aborted"))},r=()=>{n();const s=`Failed to load audio element (code: ${e.error.code})`;t?t(new Error(s)):console.error(s)},n=()=>{e.removeEventListener("canplaythrough",i),e.removeEventListener("load",i),e.removeEventListener("abort",o),e.removeEventListener("error",r)};e.addEventListener("canplaythrough",i,!1),e.addEventListener("load",i,!1),e.addEventListener("abort",o,!1),e.addEventListener("error",r,!1),e.load()}}class c{constructor(t,e){this.parent=t,_extends(this,e),this.duration=this.end-this.start,console.assert(this.duration>0,"End time must be after start time")}play(t){return this.parent.play({complete:t,speed:this.speed||this.parent.speed,end:this.end,start:this.start,loop:this.loop})}destroy(){this.parent=null}}const p=["ogg","oga","opus","m4a","mp3","mpeg","wav","aiff","wma","mid","caf"],_=["audio/mpeg","audio/ogg"],f={};function m(t){const e=_objectSpread({m4a:"audio/mp4",oga:"audio/ogg",opus:'audio/ogg; codecs="opus"',caf:'audio/x-caf; codecs="opus"'},t||{}),s=document.createElement("audio"),i={},o=/^no$/;p.forEach((t=>{const r=s.canPlayType(`audio/${t}`).replace(o,""),n=e[t]?s.canPlayType(e[t]).replace(o,""):"";i[t]=!!r||!!n})),_extends(f,i)}m();let g=0;class y extends s.EventEmitter{constructor(t){super(),this.id=g++,this._media=null,this._paused=!1,this._muted=!1,this._elapsed=0,this.init(t)}set(t,e){if(void 0===this[t])throw new Error(`Property with name ${t} does not exist.`);switch(t){case"speed":this.speed=e;break;case"volume":this.volume=e;break;case"muted":this.muted=e;break;case"loop":this.loop=e;break;case"paused":this.paused=e}return this}stop(){this._source&&(this._internalStop(),this.emit("stop"))}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh(),this._update(!0)}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}get filters(){return this._filters}set filters(t){var e;this._filters&&(null===(e=this._filters)||void 0===e||e.filter((t=>t)).forEach((t=>t.disconnect())),this._filters=null,this._source.connect(this._gain));this._filters=null!=t&&t.length?t.slice(0):null,this.refresh()}refresh(){if(!this._source)return;const t=this._media.context,e=this._media.parent;this._source.loop=this._loop||e.loop;const s=t.volume*(t.muted?0:1),i=e.volume*(e.muted?0:1),o=this._volume*(this._muted?0:1);n.setParamValue(this._gain.gain,o*i*s),n.setParamValue(this._source.playbackRate,this._speed*e.speed*t.speed),this.applyFilters()}applyFilters(){var t;if(null!==(t=this._filters)&&void 0!==t&&t.length){this._source.disconnect();let t=this._source;this._filters.forEach((e=>{t.connect(e.destination),t=e})),t.connect(this._gain)}}refreshPaused(){const t=this._media.context,e=this._media.parent,s=this._paused||e.paused||t.paused;s!==this._pausedReal&&(this._pausedReal=s,s?(this._internalStop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._elapsed%this._duration,end:this._end,speed:this._speed,loop:this._loop,volume:this._volume})),this.emit("pause",s))}play(t){const{start:e,end:s,speed:i,loop:o,volume:r,muted:n,filters:u}=t;s&&console.assert(s>e,"End time is before start time"),this._paused=!1;const{source:h,gain:a}=this._media.nodes.cloneBufferSource();this._source=h,this._gain=a,this._speed=i,this._volume=r,this._loop=!!o,this._muted=n,this._filters=u,this.refresh();const l=this._source.buffer.duration;this._duration=l,this._end=s,this._lastUpdate=this._now(),this._elapsed=e,this._source.onended=this._onComplete.bind(this),this._loop?(this._source.loopEnd=s,this._source.loopStart=e,this._source.start(0,e)):s?this._source.start(0,e,s-e):this._source.start(0,e),this.emit("start"),this._update(!0),this.enableTicker(!0)}enableTicker(t){s.Ticker.shared.remove(this._updateListener,this),t&&s.Ticker.shared.add(this._updateListener,this)}get progress(){return this._progress}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}destroy(){var t;this.removeAllListeners(),this._internalStop(),this._gain&&(this._gain.disconnect(),this._gain=null),this._media&&(this._media.context.events.off("refresh",this.refresh,this),this._media.context.events.off("refreshPaused",this.refreshPaused,this),this._media=null),null===(t=this._filters)||void 0===t||t.forEach((t=>t.disconnect())),this._filters=null,this._end=null,this._speed=1,this._volume=1,this._loop=!1,this._elapsed=0,this._duration=0,this._paused=!1,this._muted=!1,this._pausedReal=!1}toString(){return`[WebAudioInstance id=${this.id}]`}_now(){return this._media.context.audioContext.currentTime}_updateListener(){this._update()}_update(t=!1){if(this._source){const e=this._now(),s=e-this._lastUpdate;if(s>0||t){const t=this._source.playbackRate.value;this._elapsed+=s*t,this._lastUpdate=e;const i=this._duration;let o;if(this._source.loopStart){const t=this._source.loopEnd-this._source.loopStart;o=(this._source.loopStart+this._elapsed%t)/i}else o=this._elapsed%i/i;this._progress=o,this.emit("progress",this._progress,i)}}}init(t){this._media=t,t.context.events.on("refresh",this.refresh,this),t.context.events.on("refreshPaused",this.refreshPaused,this)}_internalStop(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.stop(0),this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null}}_onComplete(){if(this._source){this.enableTicker(!1),this._source.onended=null,this._source.disconnect();try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}}this._source=null,this._progress=1,this.emit("progress",1,this._duration),this.emit("end",this)}}class v{constructor(t,e){this._output=e,this._input=t}get destination(){return this._input}get filters(){return this._filters}set filters(t){if(this._filters&&(this._filters.forEach((t=>{t&&t.disconnect()})),this._filters=null,this._input.connect(this._output)),t&&t.length){this._filters=t.slice(0),this._input.disconnect();let e=null;t.forEach((t=>{null===e?this._input.connect(t.destination):e.connect(t.destination),e=t})),e.connect(this._output)}}destroy(){this.filters=null,this._input=null,this._output=null}}const b=class extends v{constructor(t){const e=t.audioContext,s=e.createBufferSource(),i=e.createGain(),o=e.createAnalyser();s.connect(o),o.connect(i),i.connect(t.destination),super(o,i),this.context=t,this.bufferSource=s,this.gain=i,this.analyser=o}get script(){return this._script||(this._script=this.context.audioContext.createScriptProcessor(b.BUFFER_SIZE),this._script.connect(this.context.destination)),this._script}destroy(){super.destroy(),this.bufferSource.disconnect(),this._script&&this._script.disconnect(),this.gain.disconnect(),this.analyser.disconnect(),this.bufferSource=null,this._script=null,this.gain=null,this.analyser=null,this.context=null}cloneBufferSource(){const t=this.bufferSource,e=this.context.audioContext.createBufferSource();e.buffer=t.buffer,n.setParamValue(e.playbackRate,t.playbackRate.value),e.loop=t.loop;const s=this.context.audioContext.createGain();return e.connect(s),s.connect(this.destination),{source:e,gain:s}}get bufferSize(){return this.script.bufferSize}};let x=b;x.BUFFER_SIZE=0;class P{init(t){this.parent=t,this._nodes=new x(this.context),this._source=this._nodes.bufferSource,this.source=t.options.source}destroy(){this.parent=null,this._nodes.destroy(),this._nodes=null;try{this._source.buffer=null}catch(t){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",t)}this._source=null,this.source=null}create(){return new y(this)}get context(){return this.parent.context}get isPlayable(){return!!this._source&&!!this._source.buffer}get filters(){return this._nodes.filters}set filters(t){this._nodes.filters=t}get duration(){return console.assert(this.isPlayable,"Sound not yet playable, no duration"),this._source.buffer.duration}get buffer(){return this._source.buffer}set buffer(t){this._source.buffer=t}get nodes(){return this._nodes}load(t){this.source?this._decode(this.source,t):this.parent.url?this._loadUrl(t):t?t(new Error("sound.url or sound.source must be set")):console.error("sound.url or sound.source must be set")}async _loadUrl(t){const e=this.parent.url,i=await s.DOMAdapter.get().fetch(e);this._decode(await i.arrayBuffer(),t)}_decode(t,e){const s=(t,s)=>{if(t)e&&e(t);else{this.parent.isLoaded=!0,this.buffer=s;const t=this.parent.autoPlayStart();e&&e(null,this.parent,t)}};if(t instanceof AudioBuffer)s(null,t);else{this.parent.context.decode(t,s)}}}const A=class{static from(t){let e={};"string"==typeof t?e.url=t:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?e.source=t:Array.isArray(t)?e.url=t:e=t,e=_objectSpread({autoPlay:!1,singleInstance:!1,url:null,source:null,preload:!1,volume:1,speed:1,complete:null,loaded:null,loop:!1},e),Object.freeze(e);const s=r().useLegacy?new d:new P;return new A(s,e)}constructor(t,e){this.media=t,this.options=e,this._instances=[],this._sprites={},this.media.init(this);const s=e.complete;this._autoPlayOptions=s?{complete:s}:null,this.isLoaded=!1,this._preloadQueue=null,this.isPlaying=!1,this.autoPlay=e.autoPlay,this.singleInstance=e.singleInstance,this.preload=e.preload||this.autoPlay,this.url=Array.isArray(e.url)?this.preferUrl(e.url):e.url,this.speed=e.speed,this.volume=e.volume,this.loop=e.loop,e.sprites&&this.addSprites(e.sprites),this.preload&&this._preload(e.loaded)}preferUrl(t){const[e]=t.map((t=>({url:t,ext:s.path.extname(t).slice(1)}))).filter((({ext:t})=>f[t])).sort(((t,e)=>p.indexOf(t.ext)-p.indexOf(e.ext)));if(!e)throw new Error("No supported file type found");return e.url}get context(){return r().context}pause(){return this.isPlaying=!1,this.paused=!0,this}resume(){return this.isPlaying=this._instances.length>0,this.paused=!1,this}get paused(){return this._paused}set paused(t){this._paused=t,this.refreshPaused()}get speed(){return this._speed}set speed(t){this._speed=t,this.refresh()}get filters(){return this.media.filters}set filters(t){this.media.filters=t}addSprites(t,e){if("object"==typeof t){const e={};for(const s in t)e[s]=this.addSprites(s,t[s]);return e}console.assert(!this._sprites[t],`Alias ${t} is already taken`);const s=new c(this,e);return this._sprites[t]=s,s}destroy(){this._removeInstances(),this.removeSprites(),this.media.destroy(),this.media=null,this._sprites=null,this._instances=null}removeSprites(t){if(t){const e=this._sprites[t];void 0!==e&&(e.destroy(),delete this._sprites[t])}else for(const t in this._sprites)this.removeSprites(t);return this}get isPlayable(){return this.isLoaded&&this.media&&this.media.isPlayable}stop(){if(!this.isPlayable)return this.autoPlay=!1,this._autoPlayOptions=null,this;this.isPlaying=!1;for(let t=this._instances.length-1;t>=0;t--)this._instances[t].stop();return this}play(t,e){let s;if("string"==typeof t){s={sprite:t,loop:this.loop,complete:e}}else"function"==typeof t?(s={},s.complete=t):s=t;if(s=_objectSpread({complete:null,loaded:null,sprite:null,end:null,start:0,volume:1,speed:1,muted:!1,loop:!1},s||{}),s.sprite){const t=s.sprite;console.assert(!!this._sprites[t],`Alias ${t} is not available`);const e=this._sprites[t];s.start=e.start+(s.start||0),s.end=e.end,s.speed=e.speed||1,s.loop=e.loop||s.loop,delete s.sprite}if(s.offset&&(s.start=s.offset),!this.isLoaded)return this._preloadQueue?new Promise((t=>{this._preloadQueue.push((()=>{t(this.play(s))}))})):(this._preloadQueue=[],this.autoPlay=!0,this._autoPlayOptions=s,new Promise(((t,e)=>{this._preload(((i,o,r)=>{this._preloadQueue.forEach((t=>t())),this._preloadQueue=null,i?e(i):(s.loaded&&s.loaded(i,o,r),t(r))}))})));(this.singleInstance||s.singleInstance)&&this._removeInstances();const i=this._createInstance();return this._instances.push(i),this.isPlaying=!0,i.once("end",(()=>{s.complete&&s.complete(this),this._onComplete(i)})),i.once("stop",(()=>{this._onComplete(i)})),i.play(s),i}refresh(){const t=this._instances.length;for(let e=0;e<t;e++)this._instances[e].refresh()}refreshPaused(){const t=this._instances.length;for(let e=0;e<t;e++)this._instances[e].refreshPaused()}get volume(){return this._volume}set volume(t){this._volume=t,this.refresh()}get muted(){return this._muted}set muted(t){this._muted=t,this.refresh()}get loop(){return this._loop}set loop(t){this._loop=t,this.refresh()}_preload(t){this.media.load(t)}get instances(){return this._instances}get sprites(){return this._sprites}get duration(){return this.media.duration}autoPlayStart(){let t;return this.autoPlay&&(t=this.play(this._autoPlayOptions)),t}_removeInstances(){for(let t=this._instances.length-1;t>=0;t--)this._poolInstance(this._instances[t]);this._instances.length=0}_onComplete(t){if(this._instances){const e=this._instances.indexOf(t);e>-1&&this._instances.splice(e,1),this.isPlaying=this._instances.length>0}this._poolInstance(t)}_createInstance(){if(A._pool.length>0){const t=A._pool.pop();return t.init(this.media),t}return this.media.create()}_poolInstance(t){t.destroy(),A._pool.indexOf(t)<0&&A._pool.push(t)}};let w=A;w._pool=[];class E extends v{constructor(){const t=window,e=new E.AudioContext,i=e.createDynamicsCompressor(),o=e.createAnalyser();o.connect(i),i.connect(e.destination),super(o,i),this.autoPause=!0,this._ctx=e,this._offlineCtx=new E.OfflineAudioContext(1,2,t.OfflineAudioContext?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),this.compressor=i,this.analyser=o,this.events=new s.EventEmitter,this.volume=1,this.speed=1,this.muted=!1,this.paused=!1,this._locked="suspended"===e.state&&("ontouchstart"in globalThis||"onclick"in globalThis),this._locked&&(this._unlock(),this._unlock=this._unlock.bind(this),document.addEventListener("mousedown",this._unlock,!0),document.addEventListener("touchstart",this._unlock,!0),document.addEventListener("touchend",this._unlock,!0)),this.onFocus=this.onFocus.bind(this),this.onBlur=this.onBlur.bind(this),globalThis.addEventListener("focus",this.onFocus),globalThis.addEventListener("blur",this.onBlur)}onFocus(){if(!this.autoPause)return;const t=this._ctx.state;"suspended"!==t&&"interrupted"!==t&&this._locked||(this.paused=this._pausedOnBlur,this.refreshPaused())}onBlur(){this.autoPause&&(this._locked||(this._pausedOnBlur=this._paused,this.paused=!0,this.refreshPaused()))}_unlock(){this._locked&&(this.playEmptySound(),"running"===this._ctx.state&&(document.removeEventListener("mousedown",this._unlock,!0),document.removeEventListener("touchend",this._unlock,!0),document.removeEventListener("touchstart",this._unlock,!0),this._locked=!1))}playEmptySound(){const t=this._ctx.createBufferSource();t.buffer=this._ctx.createBuffer(1,1,22050),t.connect(this._ctx.destination),t.start(0,0,0),"suspended"===t.context.state&&t.context.resume()}static get AudioContext(){const t=window;return t.AudioContext||t.webkitAudioContext||null}static get OfflineAudioContext(){const t=window;return t.OfflineAudioContext||t.webkitOfflineAudioContext||null}destroy(){super.destroy();const t=this._ctx;void 0!==t.close&&t.close(),globalThis.removeEventListener("focus",this.onFocus),globalThis.removeEventListener("blur",this.onBlur),this.events.removeAllListeners(),this.analyser.disconnect(),this.compressor.disconnect(),this.analyser=null,this.compressor=null,this.events=null,this._offlineCtx=null,this._ctx=null}get audioContext(){return this._ctx}get offlineContext(){return this._offlineCtx}set paused(t){t&&"running"===this._ctx.state?this._ctx.suspend():t||"suspended"!==this._ctx.state||this._ctx.resume(),this._paused=t}get paused(){return this._paused}refresh(){this.events.emit("refresh")}refreshPaused(){this.events.emit("refreshPaused")}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this._paused}decode(t,e){const s=t=>{e(new Error((null==t?void 0:t.message)||"Unable to decode file"))},i=this._offlineCtx.decodeAudioData(t,(t=>{e(null,t)}),s);i&&i.catch(s)}}const S=t=>{var e;const i=t.src;let o=null==t||null===(e=t.alias)||void 0===e?void 0:e[0];return o&&t.src!==o||(o=s.path.basename(i,s.path.extname(i))),o},C={extension:s.ExtensionType.Asset,detection:{test:async()=>!0,add:async t=>[...t,...p.filter((t=>f[t]))],remove:async t=>t.filter((e=>t.includes(e)))},loader:{name:"sound",extension:{type:[s.ExtensionType.LoadParser],priority:s.LoaderParserPriority.High},test(t){const e=s.path.extname(t).slice(1);return!!f[e]||_.some((e=>t.startsWith(`data:${e}`)))},async load(t,e){const s=await new Promise(((s,i)=>w.from(_objectSpread(_objectSpread({},e.data),{},{url:t,preload:!0,loaded(t,o){var r,n;t?i(t):s(o),null===(r=e.data)||void 0===r||null===(n=r.loaded)||void 0===n||n.call(r,t,o)}}))));return r().add(S(e),s),s},async unload(t,e){r().remove(S(e))}}};s.extensions.add(C);const L=function(t){return o=t,t}(new class{constructor(){this.init()}init(){return this.supported&&(this._webAudioContext=new E),this._htmlAudioContext=new u,this._sounds={},this.useLegacy=!this.supported,this}get context(){return this._context}get filtersAll(){return this.useLegacy?[]:this._context.filters}set filtersAll(t){this.useLegacy||(this._context.filters=t)}get supported(){return null!==E.AudioContext}add(t,e){if("object"==typeof t){const s={};for(const i in t){const o=this._getOptions(t[i],e);s[i]=this.add(i,o)}return s}if(console.assert(!this._sounds[t],`Sound with alias ${t} already exists.`),e instanceof w)return this._sounds[t]=e,e;const s=this._getOptions(e),i=w.from(s);return this._sounds[t]=i,i}_getOptions(t,e){let s;return s="string"==typeof t||Array.isArray(t)?{url:t}:t instanceof ArrayBuffer||t instanceof AudioBuffer||t instanceof HTMLAudioElement?{source:t}:t,s=_objectSpread(_objectSpread({},s),e||{}),s}get useLegacy(){return this._useLegacy}set useLegacy(t){this._useLegacy=t,this._context=!t&&this.supported?this._webAudioContext:this._htmlAudioContext}get disableAutoPause(){return!this._webAudioContext.autoPause}set disableAutoPause(t){this._webAudioContext.autoPause=!t}remove(t){return this.exists(t,!0),this._sounds[t].destroy(),delete this._sounds[t],this}get volumeAll(){return this._context.volume}set volumeAll(t){this._context.volume=t,this._context.refresh()}get speedAll(){return this._context.speed}set speedAll(t){this._context.speed=t,this._context.refresh()}togglePauseAll(){return this._context.togglePause()}pauseAll(){return this._context.paused=!0,this._context.refreshPaused(),this}resumeAll(){return this._context.paused=!1,this._context.refreshPaused(),this}toggleMuteAll(){return this._context.toggleMute()}muteAll(){return this._context.muted=!0,this._context.refresh(),this}unmuteAll(){return this._context.muted=!1,this._context.refresh(),this}removeAll(){for(const t in this._sounds)this._sounds[t].destroy(),delete this._sounds[t];return this}stopAll(){for(const t in this._sounds)this._sounds[t].stop();return this}exists(t,e=!1){const s=!!this._sounds[t];return e&&console.assert(s,`No sound matching alias '${t}'.`),s}isPlaying(){for(const t in this._sounds)if(this._sounds[t].isPlaying)return!0;return!1}find(t){return this.exists(t,!0),this._sounds[t]}play(t,e){return this.find(t).play(e)}stop(t){return this.find(t).stop()}pause(t){return this.find(t).pause()}resume(t){return this.find(t).resume()}volume(t,e){const s=this.find(t);return void 0!==e&&(s.volume=e),s.volume}speed(t,e){const s=this.find(t);return void 0!==e&&(s.speed=e),s.speed}duration(t){return this.find(t).duration}close(){return this.removeAll(),this._sounds=null,this._webAudioContext&&(this._webAudioContext.destroy(),this._webAudioContext=null),this._htmlAudioContext&&(this._htmlAudioContext.destroy(),this._htmlAudioContext=null),this._context=null,this}});L.disableAutoPause=!0,p.push("aac"),m({aac:"audio/aac"}),s.extensions.add(C);let T=class extends e.System{constructor(t){super(),this.autoPauseAndStart=!0,this.components=[],this.audioBufferCache={},_extends(this,t),(null==t?void 0:t.useLegacy)&&(L.useLegacy=!0)}resumeAll(){L.resumeAll()}pauseAll(){L.pauseAll()}stopAll(){L.stopAll()}update(){const t=this.componentObserver.clear();for(const e of t)this.componentChanged(e)}onResume(){this.autoPauseAndStart&&this.resumeAll()}onPause(){this.autoPauseAndStart&&this.pauseAll()}onDestroy(){this.components.forEach((t=>{t.onDestroy()})),this.components=[],L.removeAll()}componentChanged(t){return i(this,void 0,void 0,(function*(){"Sound"===t.componentName&&t.type===e.OBSERVER_TYPE.ADD&&this.add(t)}))}add(t){var s,o;return i(this,void 0,void 0,(function*(){const i=t.component;this.components.push(i);try{const{config:t}=i;i.state="loading";const r=yield e.resource.getResource(t.resource);!this.audioBufferCache[r.name]&&(null===(s=null==r?void 0:r.data)||void 0===s?void 0:s.audio)&&(this.audioBufferCache[r.name]=null===(o=null==r?void 0:r.data)||void 0===o?void 0:o.audio),this.audioBufferCache[r.name]&&i.onload(this.audioBufferCache[r.name])}catch(t){this.onError&&this.onError(t)}}))}};T.systemName="SoundSystem",T=function(t,e,s,i){var o,r=arguments.length,n=r<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,s):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,s,i);else for(var u=t.length-1;u>=0;u--)(o=t[u])&&(n=(r<3?o(n):r>3?o(e,s,n):o(e,s))||n);return r>3&&n&&Object.defineProperty(e,s,n),n}([e.decorators.componentObserver({Sound:[]})],T);var O=T;class k extends e.Component{constructor(){super(...arguments),this.state="unloaded",this.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0,speed:1},this.actionQueue=[],this.startTime=0}get systemContext(){return L.context.audioContext}get playing(){return!!this.buffer&&this.buffer.isPlaying}get muted(){var t;return(null===(t=this.buffer)||void 0===t?void 0:t.muted)||!1}set muted(t){this.buffer&&(this.buffer.muted=t)}get volume(){var t;return(null===(t=this.buffer)||void 0===t?void 0:t.volume)||0}set volume(t){this.buffer&&(this.buffer.volume=t)}init(t){t&&(_extends(this.config,t),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))}play(){"loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.buffer&&(this.startTime=this.systemContext.currentTime,this.buffer.play())}resume(){this.buffer&&this.buffer.resume()}pause(){this.buffer&&this.buffer.pause()}stop(){this.buffer&&this.buffer.stop()}onload(t){this.state="loaded",this.buffer=t,this.buffer.muted=this.config.muted,this.buffer.volume=this.config.volume,this.buffer.loop=this.config.loop,this.buffer.speed=this.config.speed,this.actionQueue.forEach((t=>t())),this.actionQueue.length=0}onDestroy(){this.actionQueue.length=0,this.startTime=0,this.buffer&&(this.buffer.destroy(),this.buffer=null)}}k.componentName="Sound";var j=k;return t.Sound=j,t.SoundSystem=O,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA,PIXI);globalThis.EVA.plugin.sound=globalThis.EVA.plugin.sound||_EVA_IIFE_sound;
|
package/dist/plugin-sound.cjs.js
CHANGED
|
@@ -37,6 +37,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
sound.sound.disableAutoPause = true;
|
|
41
|
+
sound.utils.extensions.push('aac');
|
|
42
|
+
sound.utils.validateFormats({
|
|
43
|
+
aac: 'audio/aac',
|
|
44
|
+
});
|
|
40
45
|
pixi_js.extensions.add(sound.soundAsset);
|
|
41
46
|
let SoundSystem = class SoundSystem extends eva_js.System {
|
|
42
47
|
constructor(obj) {
|
|
@@ -45,6 +50,9 @@ let SoundSystem = class SoundSystem extends eva_js.System {
|
|
|
45
50
|
this.components = [];
|
|
46
51
|
this.audioBufferCache = {};
|
|
47
52
|
Object.assign(this, obj);
|
|
53
|
+
if (obj === null || obj === void 0 ? void 0 : obj.useLegacy) {
|
|
54
|
+
sound.sound.useLegacy = true;
|
|
55
|
+
}
|
|
48
56
|
}
|
|
49
57
|
resumeAll() {
|
|
50
58
|
sound.sound.resumeAll();
|
|
@@ -138,7 +146,7 @@ class Sound extends eva_js.Component {
|
|
|
138
146
|
this.startTime = 0;
|
|
139
147
|
}
|
|
140
148
|
get systemContext() {
|
|
141
|
-
return sound.sound.context;
|
|
149
|
+
return sound.sound.context.audioContext;
|
|
142
150
|
}
|
|
143
151
|
get playing() {
|
|
144
152
|
if (!this.buffer)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@pixi/sound");function
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@pixi/sound"),s=require("pixi.js");function o(e,t,s,o){return new(s||(s=Promise))((function(u,i){function n(e){try{a(o.next(e))}catch(e){i(e)}}function r(e){try{a(o.throw(e))}catch(e){i(e)}}function a(e){e.done?u(e.value):new s((function(t){t(e.value)})).then(n,r)}a((o=o.apply(e,t||[])).next())}))}t.sound.disableAutoPause=!0,t.utils.extensions.push("aac"),t.utils.validateFormats({aac:"audio/aac"}),s.extensions.add(t.soundAsset);let u=class extends e.System{constructor(e){super(),this.autoPauseAndStart=!0,this.components=[],this.audioBufferCache={},Object.assign(this,e),(null==e?void 0:e.useLegacy)&&(t.sound.useLegacy=!0)}resumeAll(){t.sound.resumeAll()}pauseAll(){t.sound.pauseAll()}stopAll(){t.sound.stopAll()}update(){const e=this.componentObserver.clear();for(const t of e)this.componentChanged(t)}onResume(){this.autoPauseAndStart&&this.resumeAll()}onPause(){this.autoPauseAndStart&&this.pauseAll()}onDestroy(){this.components.forEach((e=>{e.onDestroy()})),this.components=[],t.sound.removeAll()}componentChanged(t){return o(this,void 0,void 0,(function*(){"Sound"===t.componentName&&t.type===e.OBSERVER_TYPE.ADD&&this.add(t)}))}add(t){var s,u;return o(this,void 0,void 0,(function*(){const o=t.component;this.components.push(o);try{const{config:t}=o;o.state="loading";const i=yield e.resource.getResource(t.resource);!this.audioBufferCache[i.name]&&(null===(s=null==i?void 0:i.data)||void 0===s?void 0:s.audio)&&(this.audioBufferCache[i.name]=null===(u=null==i?void 0:i.data)||void 0===u?void 0:u.audio),this.audioBufferCache[i.name]&&o.onload(this.audioBufferCache[i.name])}catch(e){this.onError&&this.onError(e)}}))}};u.systemName="SoundSystem",u=
|
|
2
2
|
/*! *****************************************************************************
|
|
3
3
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
4
|
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
@@ -13,4 +13,4 @@ MERCHANTABLITY OR NON-INFRINGEMENT.
|
|
|
13
13
|
See the Apache Version 2.0 License for specific language governing permissions
|
|
14
14
|
and limitations under the License.
|
|
15
15
|
***************************************************************************** */
|
|
16
|
-
function(e,t,s,o){var i
|
|
16
|
+
function(e,t,s,o){var u,i=arguments.length,n=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,s):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,s,o);else for(var r=e.length-1;r>=0;r--)(u=e[r])&&(n=(i<3?u(n):i>3?u(t,s,n):u(t,s))||n);return i>3&&n&&Object.defineProperty(t,s,n),n}([e.decorators.componentObserver({Sound:[]})],u);var i=u;class n extends e.Component{constructor(){super(...arguments),this.state="unloaded",this.config={resource:"",autoplay:!1,muted:!1,volume:1,loop:!1,seek:0,speed:1},this.actionQueue=[],this.startTime=0}get systemContext(){return t.sound.context.audioContext}get playing(){return!!this.buffer&&this.buffer.isPlaying}get muted(){var e;return(null===(e=this.buffer)||void 0===e?void 0:e.muted)||!1}set muted(e){this.buffer&&(this.buffer.muted=e)}get volume(){var e;return(null===(e=this.buffer)||void 0===e?void 0:e.volume)||0}set volume(e){this.buffer&&(this.buffer.volume=e)}init(e){e&&(Object.assign(this.config,e),this.config.autoplay&&this.actionQueue.push(this.play.bind(this)))}play(){"loaded"!==this.state&&this.actionQueue.push(this.play.bind(this)),this.buffer&&(this.startTime=this.systemContext.currentTime,this.buffer.play())}resume(){this.buffer&&this.buffer.resume()}pause(){this.buffer&&this.buffer.pause()}stop(){this.buffer&&this.buffer.stop()}onload(e){this.state="loaded",this.buffer=e,this.buffer.muted=this.config.muted,this.buffer.volume=this.config.volume,this.buffer.loop=this.config.loop,this.buffer.speed=this.config.speed,this.actionQueue.forEach((e=>e())),this.actionQueue.length=0}onDestroy(){this.actionQueue.length=0,this.startTime=0,this.buffer&&(this.buffer.destroy(),this.buffer=null)}}n.componentName="Sound";var r=n;exports.Sound=r,exports.SoundSystem=i;
|
package/dist/plugin-sound.d.ts
CHANGED
package/dist/plugin-sound.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { System, decorators, OBSERVER_TYPE, resource, Component } from '@eva/eva.js';
|
|
2
|
-
import {
|
|
2
|
+
import { sound, utils, soundAsset } from '@pixi/sound';
|
|
3
3
|
import { extensions } from 'pixi.js';
|
|
4
4
|
|
|
5
5
|
/*! *****************************************************************************
|
|
@@ -33,6 +33,11 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
sound.disableAutoPause = true;
|
|
37
|
+
utils.extensions.push('aac');
|
|
38
|
+
utils.validateFormats({
|
|
39
|
+
aac: 'audio/aac',
|
|
40
|
+
});
|
|
36
41
|
extensions.add(soundAsset);
|
|
37
42
|
let SoundSystem = class SoundSystem extends System {
|
|
38
43
|
constructor(obj) {
|
|
@@ -41,6 +46,9 @@ let SoundSystem = class SoundSystem extends System {
|
|
|
41
46
|
this.components = [];
|
|
42
47
|
this.audioBufferCache = {};
|
|
43
48
|
Object.assign(this, obj);
|
|
49
|
+
if (obj === null || obj === void 0 ? void 0 : obj.useLegacy) {
|
|
50
|
+
sound.useLegacy = true;
|
|
51
|
+
}
|
|
44
52
|
}
|
|
45
53
|
resumeAll() {
|
|
46
54
|
sound.resumeAll();
|
|
@@ -134,7 +142,7 @@ class Sound extends Component {
|
|
|
134
142
|
this.startTime = 0;
|
|
135
143
|
}
|
|
136
144
|
get systemContext() {
|
|
137
|
-
return sound.context;
|
|
145
|
+
return sound.context.audioContext;
|
|
138
146
|
}
|
|
139
147
|
get playing() {
|
|
140
148
|
if (!this.buffer)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-sound",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1-beta.0",
|
|
4
4
|
"description": "@eva/plugin-sound",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-sound.esm.js",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "2.0.
|
|
21
|
+
"@eva/eva.js": "2.0.1-beta.0",
|
|
22
22
|
"eventemitter3": "^3.1.2",
|
|
23
|
-
"pixi.js": "^8.
|
|
23
|
+
"pixi.js": "^8.8.1",
|
|
24
24
|
"@pixi/sound": "^6.0.1"
|
|
25
25
|
}
|
|
26
26
|
}
|