Skip to content

Commit

Permalink
Cancel fade when mute is called on a sound
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfire authored and bhaskarp-vg committed Feb 7, 2018
1 parent 3c71df5 commit 5d96fdf
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,11 @@
if (sound) {
sound._muted = muted;

// Cancel active fade and set the volume to the end value.
if (sound._interval) {
self._stopFade(sound._id);
}

if (self._webAudio && sound._node) {
sound._node.gain.setValueAtTime(muted ? 0 : sound._volume, Howler.ctx.currentTime);
} else if (sound._node) {
Expand Down Expand Up @@ -1171,6 +1176,10 @@
stepLen = 4;
}

// Store the value being faded to.
sound._fadeTo = to;

// Update the volume value on each interval tick.
sound._interval = setInterval(function() {
// Update the volume amount, but only if the volume should change.
if (steps > 0) {
Expand Down Expand Up @@ -1200,6 +1209,7 @@
if ((to < from && vol <= to) || (to > from && vol >= to)) {
clearInterval(sound._interval);
sound._interval = null;
sound._fadeTo = null;
self.volume(to, sound._id);
self._emit('fade', sound._id);
}
Expand All @@ -1223,6 +1233,8 @@

clearInterval(sound._interval);
sound._interval = null;
self.volume(sound._fadeTo, id);
sound._fadeTo = null;
self._emit('fade', id);
}

Expand Down

0 comments on commit 5d96fdf

Please sign in to comment.