Abstract updating volume

This commit is contained in:
Jordan Eldredge 2015-01-28 21:20:31 -08:00
parent aa7f2ec362
commit b9072bc97c
2 changed files with 10 additions and 3 deletions

View file

@ -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;

View file

@ -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) {