Skip to content

Commit

Permalink
wait for 5 sec for next request if an error occurs, to avoid flooding…
Browse files Browse the repository at this point in the history
… the api
  • Loading branch information
eiriklv committed Jun 24, 2014
1 parent e586633 commit 9426c86
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions player/modules/spotify/player/player.js
Expand Up @@ -40,7 +40,7 @@ Player.prototype.play = function (song) {
// handle error on mp3 stream
this.current.on('error', function (err) {
debug(err);
this.handlePlayEnd.call(this, song, spotify);
this.handlePlayEnd.call(this, err, song, spotify);
}.bind(this));

// decode and play the mp3 stream
Expand All @@ -49,25 +49,26 @@ Player.prototype.play = function (song) {
.pipe(new Speaker())
.on('finish', function () {
debug('finished playing song');
this.handlePlayEnd.call(this, song, spotify);
this.handlePlayEnd.call(this, null, song, spotify);
}.bind(this))
.on('error', function (err) {
debug(err);
this.handlePlayEnd.call(this, song, spotify);
this.handlePlayEnd.call(this, err, song, spotify);
}.bind(this));

}.bind(this));
}.bind(this));
};

// handle end of play (either success or error)
Player.prototype.handlePlayEnd = function (song, spotify) {
Player.prototype.handlePlayEnd = function (err, song, spotify) {
// if the song is not available, just skip it and move on
spotify.disconnect();
this.current = null;

// update queueitem to playing: false and queue: false
this.queue.update(song, function (err, product) {
this.queue.update(song, function (error, product) {
if (err) return setTimeout(this.next.bind(this), 5000);
this.next();
}.bind(this));
};
Expand Down

0 comments on commit 9426c86

Please sign in to comment.