From b742b684ca931de2f906a0c24ee773d7c7dfad0a Mon Sep 17 00:00:00 2001 From: Jer Noble Date: Thu, 20 Feb 2014 11:39:50 -0800 Subject: [PATCH 1/1] Added volume and muted support. --- sound.html | 49 +++++++++++++++++++++++++++++++++++++++++++------ sound.js | 26 ++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/sound.html b/sound.html index 34889fa..82020e6 100644 --- a/sound.html +++ b/sound.html @@ -4,15 +4,52 @@ sound test - + - +
+ + + + +
\ No newline at end of file diff --git a/sound.js b/sound.js index f823be3..843be80 100644 --- a/sound.js +++ b/sound.js @@ -129,8 +129,9 @@ Sound.prototype = { if (this._ended && this._playbackRate > 0) this.setCurrentTime(0); - if (this._paused) { + if (this._paused || this._ended) { this._paused = false; + this._ended = false; this.dispatchEventAsync(new CustomEvent('play')); if (this._readyState < this.READY.FUTURE_DATA) @@ -162,7 +163,7 @@ Sound.prototype = { this._autoplay = false; if (!this._paused) { - this._paused = false; + this._paused = true; this.dispatchEventAsync(new CustomEvent('timeupdate')); this.dispatchEventAsync(new CustomEvent('pause')); } @@ -319,12 +320,29 @@ Sound.prototype = { }, setVolume: function(volume) { + if (this._volume == volume) + return; + this._volume = volume; - if (!this.gainNode) + this.dispatchEventAsync(new CustomEvent('volumechange')); + + if (this.gainNode) + this.gainNode.gain.value = this._muted ? 0 : this._volume; + }, + + getMuted: function() { + return this._muted; + }, + + setMuted: function(muted) { + if (this._muted == muted) return; - this.gainNode.gain.value = volume; + this._muted = muted; this.dispatchEventAsync(new CustomEvent('volumechange')); + + if (this.gainNode) + this.gainNode.gain.value = this._muted ? 0 : this._volume; }, }; -- 2.40.1