diff --git a/src/components/sound.js b/src/components/sound.js index 920b30e1528..a2e48057cc4 100644 --- a/src/components/sound.js +++ b/src/components/sound.js @@ -12,6 +12,8 @@ module.exports.Component = registerComponent('sound', { autoplay: {default: false}, distanceModel: {default: 'inverse', oneOf: ['linear', 'inverse', 'exponential']}, loop: {default: false}, + loopStart: {default: 0}, + loopEnd: {default: 0}, maxDistance: {default: 10000}, on: {default: ''}, poolSize: {default: 1}, @@ -58,6 +60,16 @@ module.exports.Component = registerComponent('sound', { sound.setRolloffFactor(data.rolloffFactor); } sound.setLoop(data.loop); + sound.setLoopStart(data.loopStart); + + // With a loop start specified without a specified loop end, the end of the loop should be the end of the file + if(data.loopStart != 0 && data.loopEnd == 0){ + sound.setLoopEnd(sound.buffer.duration); + } + else { + sound.setLoopEnd(data.loopEnd); + } + sound.setVolume(data.volume); sound.isPaused = false; } @@ -80,7 +92,7 @@ module.exports.Component = registerComponent('sound', { // Remove this key from cache, otherwise we can't play it again THREE.Cache.remove(data.src); - if (self.data.autoplay || self.mustPlay) { self.playSound(); } + if (self.data.autoplay || self.mustPlay) { self.playSound(this.processSound); } self.el.emit('sound-loaded', self.evtDetail, false); }); } @@ -208,6 +220,7 @@ module.exports.Component = registerComponent('sound', { if (!this.loaded) { warn('Sound not loaded yet. It will be played once it finished loading'); this.mustPlay = true; + this.processSound = processSound; return; } @@ -231,6 +244,7 @@ module.exports.Component = registerComponent('sound', { } this.mustPlay = false; + this.processSound = undefined; }, /**