-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#5364 Bugfix : Sound : processSound callback saved and used with loaded + mustPlay #5365
Changes from 3 commits
bf3e196
f91140a
61a5455
6d48043
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}, | ||
|
@@ -32,6 +34,7 @@ module.exports.Component = registerComponent('sound', { | |
this.pool = new THREE.Group(); | ||
this.loaded = false; | ||
this.mustPlay = false; | ||
this.processSound = undefined; // Saved callback for the mustPlay mechanic | ||
|
||
// Don't pass evt because playSound takes a function as parameter. | ||
this.playSoundBound = function () { self.playSound(); }; | ||
|
@@ -58,6 +61,14 @@ 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
we always use brackets for if statements There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, will change. |
||
|
||
sound.setVolume(data.volume); | ||
sound.isPaused = false; | ||
} | ||
|
@@ -80,7 +91,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 +219,9 @@ module.exports.Component = registerComponent('sound', { | |
if (!this.loaded) { | ||
warn('Sound not loaded yet. It will be played once it finished loading'); | ||
this.mustPlay = true; | ||
if(processSound){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. single liner:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if the if statement is necessary. probably can just do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, will do. |
||
this.processSound = processSound; | ||
} | ||
return; | ||
} | ||
|
||
|
@@ -231,6 +245,7 @@ module.exports.Component = registerComponent('sound', { | |
} | ||
|
||
this.mustPlay = false; | ||
this.processSound = undefined; | ||
}, | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not need to explicitly assign variable to undefined. already undefined if it doesn't exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where / when is this callback called? If a callback variable should be named accordingly:
playSoundCallback
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used at line 96 : if (self.data.autoplay || self.mustPlay) { self.playSound(this.processSound); }
Yes i understand it looks useless to explicitely declare it undefined but it was giving me a chance to add a comment here. I'll remove it.