Skip to content

Commit

Permalink
Fixed problems with server.js + cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
mpj committed May 5, 2012
1 parent 2664c5b commit 7401f35
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions server/server.js
Expand Up @@ -53,20 +53,25 @@ var handle = query.observe({
*/
function checkForSkipping(playlistItemId) {
var pli = PlaylistItems.findOne(playlistItemId),
isStillPlaying = !!pli.playing_since,
isPastEnd = ((Number(new Date()) - pli.playing_since + pli.position)) > pli.duration;

if (!isStillPlaying) {
// Not playing anymore (somebody probably changed tracks, or scrubbed)
return;
}

if(isPastEnd) {
// Is playing, and has went past the end of the track.
// This means that we should skip to the next track.
var nextSibling = findNextSibling(pli);
if (nextSibling) player.play(nextSibling);
now = Number(new Date()),
hasPlayedPastEnd = !!pli.playing_since &&
now - pli.playing_since + pli.position > pli.duration;

if (hasPlayedPastEnd) {

// Is playing, and has went past the end of the track.
// This means that we should skip to the next track.
var nextSibling = findNextSibling(pli);
if (nextSibling) player.play(nextSibling);

} else {

// Do nothing - this playlistItem did not play past
// end when we expected it to - somebody probably
// changed tracks, or scrubbed.

}

}

/*
Expand Down

0 comments on commit 7401f35

Please sign in to comment.