diff --git a/server/djrandom/frontend/static/player.js b/server/djrandom/frontend/static/player.js index 09fa4bf906dbcc53e91a66fbc49f803c2311ff16..31b1dcc557be8ad71d6ee09cb171dfe8048ad408 100644 --- a/server/djrandom/frontend/static/player.js +++ b/server/djrandom/frontend/static/player.js @@ -117,7 +117,7 @@ djr.Playlist.prototype.addChunk = function(playlist_chunk) { var songs = [], i; for (i = 0; i < playlist_chunk.songs.length; i++) { var song = playlist_chunk.songs[i]; - if (this.song_map[song]) { + if (this.song_map[song] != null) { continue; } songs.push(song); @@ -133,6 +133,11 @@ djr.Playlist.prototype.addChunk = function(playlist_chunk) { } }; +// Return the songs for a specific chunk. +djr.Playlist.prototype.getChunkSongs = function(chunk_id) { + return this.chunk_map[chunk_id].songs; +}; + // Remove a chunk (by ID). djr.Playlist.prototype.removeChunk = function(chunk_id) { djr.debug('removing chunk ' + chunk_id); @@ -221,7 +226,12 @@ djr.Player.prototype.search = function(query) { } var chunk_id = player.playlist.addChunk(new djr.PlaylistChunk(songs)); - djr.debug('search: new chunk ' + chunk_id); + if (chunk_id < 0) { + djr.debug('All the results are already in the playlist.'); + return; + } + songs = player.playlist.getChunkSongs(chunk_id); + djr.debug('search: new chunk ' + chunk_id + ', ' + songs.length + ' songs'); player.backend.getHtmlForSongs(songs, function(songs_html) { var chunk_div = 'chunk_' + chunk_id;