Skip to content

Commit

Permalink
34. jQuery: Seek Bars – Assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
Colleen committed Sep 29, 2015
1 parent ea64c70 commit 40ffe0b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
4 changes: 2 additions & 2 deletions album.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ <h3 class="artist-name"></h3>
<div class="fill"></div>
<div class="thumb"></div>
</div>
<div class="current-time">2:30</div>
<div class="total-time">4:45</div>
<div class="current-time"></div>
<div class="total-time"></div>
</div>
</div>
<div class="control-group volume">
Expand Down
35 changes: 33 additions & 2 deletions scripts/album.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var createSongRow = function(songNumber, songName, songLength) {
'<tr class="album-view-song-item">'
+ ' <td class="song-item-number" data-song-number="' + songNumber + '">' + songNumber + '</td>'
+ ' <td class="song-item-title">' + songName + '</td>'
+ ' <td class="song-item-duration">' + songLength + '</td>'
+ ' <td class="song-item-duration">' + filterTimeCode(songLength) + '</td>'
+ '</tr>'
;

Expand Down Expand Up @@ -117,12 +117,41 @@ var setCurrentAlbum = function(album) {
}
};

var setCurrentTimeInPlayerBar = function(currentTime) {
var $currentTimeElement = $('.seek-control .current-time');
$currentTimeElement.text(currentTime);
};

var setTotalTimeInPlayerBar = function(totalTime) {
var $totalTimeElement = $('.seek-control .total-time');
$totalTimeElement.text(totalTime);
};

var filterTimeCode = function(timeInSeconds) {
var seconds = Number.parseFloat(timeInSeconds);
var wholeSeconds = Math.floor(seconds);
var minutes = Math.floor(wholeSeconds / 60);

var remainingSeconds = wholeSeconds % 60;
var output = minutes + ':';

if (remainingSeconds < 10) {
output += '0';
}

output += remainingSeconds;
return output;
};

var updateSeekBarWhileSongPlays = function() {
if (currentSoundFile) {
currentSoundFile.bind('timeupdate', function(event) {
var seekBarFillRatio = this.getTime() / this.getDuration();
var currentTime = this.getTime();
var songLength = this.getDuration();
var seekBarFillRatio = currentTime / songLength;
var $seekBar = $('.seek-control .seek-bar');
updateSeekPercentage($seekBar, seekBarFillRatio);
setCurrentTimeInPlayerBar(filterTimeCode(currentTime));
});
}
};
Expand Down Expand Up @@ -178,6 +207,8 @@ var updatePlayerBarSong = function() {
$('.currently-playing .artist-song-mobile').text(currentSongFromAlbum.name + " - " + currentAlbum.artist);

$('.main-controls .play-pause').html(playerBarPauseButton);

setTotalTimeInPlayerBar(filterTimeCode(currentSongFromAlbum.length));
};

var trackIndex = function(album, song) {
Expand Down

0 comments on commit 40ffe0b

Please sign in to comment.