@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 3.18 kB
JavaScript
import{O as t}from"./index-BPURObVq.esm.min.js";import{A as e}from"./abstractSoundSource-C5k4Xume.esm.min.js";import{A as s}from"./spatialWebAudioUpdaterComponent-LOlF6N8J.esm.min.js";class n extends e{constructor(e,s,n){super(e,s,n,3),this._newestInstance=null,this._privateInstances=new Set,this._state=1,this._instances=this._privateInstances,this.onEndedObservable=new t,this._onInstanceEnded=t=>{this._newestInstance===t&&(this._newestInstance=null),t.onStateChangedObservable.removeCallback(this._onInstanceStateChanged),this._privateInstances.delete(t),0===this._instances.size&&(this._state=1,this.onEndedObservable.notifyObservers(this)),t.dispose(),this.engine._onSoundPlaybackStateChanged()},this._onInstanceStateChanged=t=>{this.engine._onSoundPlaybackStateChanged()}}get activeInstancesCount(){return this._instances.size}get autoplay(){return this._options.autoplay}get currentTime(){const t=this._getNewestInstance();return t?t.currentTime:0}set currentTime(t){this.startOffset=t;const e=this._getNewestInstance();e&&(e.currentTime=t)}get loop(){return this._options.loop}set loop(t){this._options.loop=t;const e=this._instances.values();for(let s=e.next();!s.done;s=e.next())s.value.loop=t}get maxInstances(){return this._options.maxInstances}set maxInstances(t){this._options.maxInstances=t}get startOffset(){return this._options.startOffset}set startOffset(t){this._options.startOffset=t}get state(){return this._state}dispose(){super.dispose(),this.stop(),this._newestInstance=null,this._privateInstances.clear(),this.onEndedObservable.clear()}pause(){const t=this._instances.values();for(let e=t.next();!e.done;e=t.next())e.value.pause();this._state=5,this.engine._onSoundPlaybackStateChanged()}resume(t){if(5!==this._state)return;const e=this._instances.values();for(let s=e.next();!s.done;s=e.next())s.value.resume(t);this._state=3,this.engine._onSoundPlaybackStateChanged()}_beforePlay(t){5===this.state&&this._instances.size>0?this.resume():(t.onEndedObservable.addOnce(this._onInstanceEnded),t.onStateChangedObservable.add(this._onInstanceStateChanged),this._privateInstances.add(t),this._newestInstance=t)}_afterPlay(t){this._state=t.state,this.engine._onSoundPlaybackStateChanged()}_getNewestInstance(){if(0===this._instances.size)return null;if(!this._newestInstance){const t=this._instances.values();for(let e=t.next();!e.done;e=t.next())this._newestInstance=e.value}return this._newestInstance}_setState(t){this._state=t}_stopExcessInstances(){if(this.maxInstances<1/0){const t=Array.from(this._instances).filter(t=>3===t.state),e=t.length-this.maxInstances;for(let s=0;s<e;s++)t[s].stop()}}}class a extends s{constructor(e){super(e.engine,2),this._state=1,this.onEndedObservable=new t,this.onErrorObservable=new t,this.onStateChangedObservable=new t,this._sound=e}get state(){return this._state}dispose(){super.dispose(),this.stop(),this.onEndedObservable.clear(),this.onStateChangedObservable.clear()}_setState(t){this._state!==t&&(this._state=t,this.onStateChangedObservable.notifyObservers(this),1===this._state&&this.onEndedObservable.notifyObservers(this))}}export{n as A,a as _};
//# sourceMappingURL=abstractSoundInstance-CT5dRXOE.esm.min.js.map