From 8e0638512dd5593d0ddff76a60c17f39a7313131 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Mon, 8 Aug 2011 16:27:28 -0700 Subject: [PATCH] automatically play next track --- beetsplug/web/static/beets.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/beetsplug/web/static/beets.js b/beetsplug/web/static/beets.js index 57be64599..c2dedbf97 100644 --- a/beetsplug/web/static/beets.js +++ b/beetsplug/web/static/beets.js @@ -221,6 +221,7 @@ var AppView = Backbone.View.extend({ }, initialize: function() { this.playingItem = null; + this.shownItems = null; // Not sure why these events won't bind automatically. this.$('audio').bind({ @@ -230,6 +231,7 @@ var AppView = Backbone.View.extend({ }); }, showItems: function(items) { + this.shownItems = items; $('#results').empty(); items.each(function(item) { var view = new ItemEntryView({model: item}); @@ -267,6 +269,19 @@ var AppView = Backbone.View.extend({ }, audioEnded: function() { this.playingItem.entryView.setPlaying(false); + + // Try to play the next track. + var idx = this.shownItems.indexOf(this.playingItem); + if (idx == -1) { + // Not in current list. + return; + } + var nextIdx = idx + 1; + if (nextIdx >= this.shownItems.size()) { + // End of list. + return; + } + this.playItem(this.shownItems.at(nextIdx)); } }); var app = new AppView();