Clean up media.js

This commit is contained in:
Jordan Eldredge 2014-11-12 22:48:13 -08:00
parent ece10b253f
commit 61a8e5bb8f
2 changed files with 25 additions and 32 deletions

View file

@ -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)
];
}
}

View file

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