src/components/sound.js
function () {
    var el = this.el;
    var i;
    var sceneEl = el.sceneEl;
    var self = this;
    var sound;

    if (this.pool.children.length > 0) {
      this.stopSound();
      el.removeObject3D('sound');
    }

    // Only want one AudioListener. Cache it on the scene.
    var listener = this.listener = sceneEl.audioListener || new THREE.AudioListener();
    sceneEl.audioListener = listener;

    if (sceneEl.camera) {
      sceneEl.camera.add(listener);
    }

    // Wait for camera if necessary.
    sceneEl.addEventListener('camera-set-active', function (evt) {
      evt.detail.cameraEl.getObject3D('camera').add(listener);
    });

    // Create [poolSize] audio instances and attach them to pool
    this.pool = new THREE.Group();
    for (i = 0; i < this.data.poolSize; i++) {
      sound = this.data.positional
        ? new THREE.PositionalAudio(listener)
        : new THREE.Audio(listener);
      this.pool.add(sound);
    }
    el.setObject3D(this.attrName, this.pool);

    for (i = 0; i < this.pool.children.length; i++) {
      sound = this.pool.children[i];
      sound.onEnded = function () {
        this.isPlaying = false;
        self.el.emit('sound-ended', self.evtDetail, false);
      };
    }
  }
function () {
    var el = this.el;
    var i;
    var sceneEl = el.sceneEl;
    var self = this;
    var sound;

    if (this.pool.children.length > 0) {
      this.stopSound();
      el.removeObject3D('sound');
    }

    // Only want one AudioListener. Cache it on the scene.
    var listener = this.listener = sceneEl.audioListener || new THREE.AudioListener();
    sceneEl.audioListener = listener;

    if (sceneEl.camera) {
      sceneEl.camera.add(listener);
    }

    // Wait for camera if necessary.
    sceneEl.addEventListener('camera-set-active', function (evt) {
      evt.detail.cameraEl.getObject3D('camera').add(listener);
    });

    // Create [poolSize] audio instances and attach them to pool
    this.pool = new THREE.Group();
    for (i = 0; i < this.data.poolSize; i++) {
      sound = this.data.positional
        ? new THREE.PositionalAudio(listener)
        : new THREE.Audio(listener);
      this.pool.add(sound);
    }
    el.setObject3D(this.attrName, this.pool);

    for (i = 0; i < this.pool.children.length; i++) {
      sound = this.pool.children[i];
      sound.onEnded = function () {
        this.isPlaying = false;
        self.el.emit('sound-ended', self.evtDetail, false);
      };
    }
  }
function ( ) { var el = this . el ; var i ; var sceneEl = el . sceneEl ; var self = this ; var sound ; if ( this . pool . children . length > 0 ) { this . stopSound ( ) ; el . removeObject3D ( 'sound' ) ; } // Only want one AudioListener. Cache it on the scene. var listener = this . listener = sceneEl . audioListener || new THREE . AudioListener ( ) ; sceneEl . audioListener = listener ; if ( sceneEl . camera ) { sceneEl . camera . add ( listener ) ; } // Wait for camera if necessary. sceneEl . addEventListener ( 'camera-set-active' , function ( evt ) { evt . detail . cameraEl . getObject3D ( 'camera' ) . add ( listener ) ; } ) ; // Create [poolSize] audio instances and attach them to pool this . pool = new THREE . Group ( ) ; for ( i = 0 ; i < this . data . poolSize ; i ++ ) { sound = this . data . positional ? new THREE . PositionalAudio ( listener ) : new THREE . Audio ( listener ) ; this . pool . add ( sound ) ; } el . setObject3D ( this . attrName , this . pool ) ; for ( i = 0 ; i < this . pool . children . length ; i ++ ) { sound = this . pool . children [ i ] ; sound . onEnded = function ( ) { this . isPlaying = false ; self . el . emit ( 'sound-ended' , self . evtDetail , false ) ; } ; } }
Removes current sound object, creates new sound object, adds to entity.

@returns {object} sound
Removes current sound object creates new sound object adds to entity .