From 61a8e5bb8fd8cc64d3549ca759e566b3c4d5f8a1 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 12 Nov 2014 22:48:13 -0800 Subject: [PATCH] Clean up media.js --- media.js | 40 ++++++++++------------------------------ winamp.js | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/media.js b/media.js index 51ae6969..4916d2c7 100644 --- a/media.js +++ b/media.js @@ -9,12 +9,6 @@ function Media (audioId) { this.timeRemaining = function() { return this.audio.duration - this.audio.currentTime; } - this.timeElapsedObject = function() { - return this._timeObject(this.timeElapsed()); - } - this.timeRemainingObject = function() { - return this._timeObject(this.timeRemaining()); - } this.percentComplete = function() { return (this.audio.currentTime / this.audio.duration) * 100; } @@ -22,55 +16,41 @@ function Media (audioId) { /* Actions */ this.previous = function() { // Implement this when we support playlists - }; + } this.play = function() { this.audio.play(); - }; + } this.pause = function() { this.audio.pause(); - }; + } this.stop = function() { this.audio.pause(); this.audio.currentTime = 0; - }; + } this.next = function() { // Implement this when we support playlists - }; + } this.toggleRepeat = function() { this.audio.loop = !this.audio.loop; - }; + } this.toggleShuffle = function() { // Not implemented - }; + } /* Actions with arguments */ this.seekToPercentComplete = function(percent) { this.audio.currentTime = this.audio.duration * (percent/100); - }; + } // From 0-1 this.setVolume = function(volume) { this.audio.volume = volume; - }; + } this.loadFile = function(file) { this.audio.setAttribute('src', file); - }; + } /* Listeners */ this.addEventListener = function(event, callback) { this.audio.addEventListener(event, callback); - }; - - /* Helpers */ - // TODO: Move this to the Winamp object - this._timeObject = function(time) { - var minutes = Math.floor(time / 60); - var seconds = time - (minutes * 60); - - return [ - Math.floor(minutes / 10), - Math.floor(minutes % 10), - Math.floor(seconds / 10), - Math.floor(seconds % 10) - ]; } } diff --git a/winamp.js b/winamp.js index a47e691f..2d2df37f 100755 --- a/winamp.js +++ b/winamp.js @@ -267,10 +267,10 @@ function Winamp () { var shadeMinusCharacter = ' '; if(this.nodes.time.classList.contains('countdown')) { - digits = this.media.timeRemainingObject(); + digits = this._timeObject(this.media.timeRemaining()); var shadeMinusCharacter = '-'; } else { - digits = this.media.timeElapsedObject(); + digits = this._timeObject(this.media.timeElapsed()); } this.font.displayCharacterInNode(shadeMinusCharacter, document.getElementById('shade-minus-sign')); @@ -345,6 +345,19 @@ function Winamp () { this.updateTime(); } + /* Helpers */ + this._timeObject = function(time) { + var minutes = Math.floor(time / 60); + var seconds = time - (minutes * 60); + + return [ + Math.floor(minutes / 10), + Math.floor(minutes % 10), + Math.floor(seconds / 10), + Math.floor(seconds % 10) + ]; + } + // TODO: Move to font.js function digitHtml(digit) { horizontalOffset = digit * 9;