From b9072bc97c05c21602f10132baf22b7006ff8741 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 28 Jan 2015 21:20:31 -0800 Subject: [PATCH] Abstract updating volume --- js/main-window.js | 4 +++- js/winamp.js | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/js/main-window.js b/js/main-window.js index 7f09d091..f961b3d0 100644 --- a/js/main-window.js +++ b/js/main-window.js @@ -196,6 +196,7 @@ MainWindow = { window.addEventListener('changeState', function() { self.changeState(); }); window.addEventListener('titleUpdated', function() { self.updateTitle(); }); window.addEventListener('channelCountUpdated', function() { self.updateChannelCount(); }); + window.addEventListener('volumeChanged', function() { self.updateVolume(); }); this.nodes.window.addEventListener('dragenter', this.dragenter.bind(this)); this.nodes.window.addEventListener('dragover', this.dragover.bind(this)); @@ -290,7 +291,8 @@ MainWindow = { this.updateTime(); }, - setVolume: function(volume) { + updateVolume: function() { + var volume = this.winamp.getVolume(); var percent = volume / 100; var sprite = Math.round(percent * 28); var offset = (sprite - 1) * 15; diff --git a/js/winamp.js b/js/winamp.js index 4a110a23..89990fc1 100755 --- a/js/winamp.js +++ b/js/winamp.js @@ -21,7 +21,8 @@ Winamp = { toggleTimeMode: new Event('toggleTimeMode'), changeState: new Event('changeState'), titleUpdated: new Event('titleUpdated'), - channelCountUpdated: new Event('channelCountUpdated') + channelCountUpdated: new Event('channelCountUpdated'), + volumeChanged: new Event('volumeChanged') } this.setVolume(options.volume); @@ -97,6 +98,10 @@ Winamp = { return this.media.channels(); }, + getVolume: function() { + return Math.round(this.media.getVolume() * 100); + }, + seekToPercentComplete: function(percent) { this.media.seekToPercentComplete(percent); }, @@ -147,7 +152,7 @@ Winamp = { var percent = volume / 100; this.media.setVolume(percent); - this.mainWindow.setVolume(volume); + window.dispatchEvent(this.events.volumeChanged); }, incrementVolumeBy: function(ammount) {