Skip to content

Commit

Permalink
autoNext is now configurable. Good for when client is offline and we …
Browse files Browse the repository at this point in the history
…don't want queue to skip through all tracks to the end [Delivers: #36027709]
  • Loading branch information
Dan Kantor committed Sep 14, 2012
1 parent b6f5632 commit 4e1386b
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ function PlayQueue(opts){
// playing again if we are more than 10 seconds in
this.smart_previous = true;

// Boolean if we should automatically go to next song when current
// song ends. Good to set to false if client goes offline so it
// doesn't skip through all songs
this.autoNext = true;

// Number of milliseconds we should wait before deciding the current
// song loading is not going to load and we should call next
Expand Down Expand Up @@ -570,21 +574,35 @@ PlayQueue.prototype.timeoutLoading = function(){
// Called automatically when a song ends
// If there are no more songs in the list, calles stop
PlayQueue.prototype.next = function(e){
if(this.queueNumber < this.getList().length - 1){
this.queueNumber++;
this.play(this.queueNumber);
this.dispatchEvent('nextTrack',
{
'song': this.getSong(),
'queueNumber': this.queueNumber
}
);
}
else{
if (e && e.type === 'ended'){
// not user initiated
if(e && e.type === 'ended'){
if(this.queueNumber < this.getList().length - 1
&& this.autoNext === true){
this._goNext();
}
else{
this.stop();
}
}
// user initiated
else{
if(this.queueNumber < this.getList().length - 1){
this._goNext();
}
}
}

// actually skip to the next song
PlayQueue.prototype._goNext = function(e){
this.queueNumber++;
this.play(this.queueNumber);
this.dispatchEvent(
'nextTrack',
{
'song': this.getSong(),
'queueNumber': this.queueNumber
}
);
}

// This is called to go to the previous song in the list
Expand Down

0 comments on commit 4e1386b

Please sign in to comment.