Skip to content
Snippets Groups Projects
Commit 17cb61d4 authored by ale's avatar ale
Browse files

handle the initial case when playlist id = null

parent 400c15d1
No related branches found
No related tags found
No related merge requests found
......@@ -48,18 +48,24 @@ djr.Player.prototype.clearPlaylist = function() {
};
// Set the playlist to a new set of songs.
djr.Player.prototype.setPlaylist = function(uuid, hashes) {
djr.debug('set playlist: ' + uuid + ' - ' + hashes.join(', '));
this.curPlaylistId = uuid;
djr.Player.prototype.setPlaylist = function(hashes) {
djr.debug('set playlist: ' + this.curPlaylistId + ' - ' + hashes.join(', '));
this.curPlaylist = hashes;
this.curIdx = -1;
};
// Add songs to the playlist.
// Add songs to the playlist, do not add songs already in there.
djr.Player.prototype.extendPlaylist = function(hashes) {
var i;
var i, map = {};
for (i = 0; i < this.curPlaylist.length; i++) {
map[this.curPlaylist[i]] = 1;
}
for (i = 0; i < hashes.length; i++) {
if (map[hashes[i]]) {
continue;
}
this.curPlaylist.push(hashes[i]);
map[hashes[i]] = 1;
}
};
......@@ -84,7 +90,8 @@ djr.Player.prototype.loadPlaylist = function(uuid, callback) {
dataType: 'json',
context: this,
success: function(data, status, jqxhr) {
this.setPlaylist(uuid, data.songs);
this.curPlaylistId = uuid;
this.setPlaylist(data.songs);
if (callback) {
callback();
}
......@@ -94,9 +101,13 @@ djr.Player.prototype.loadPlaylist = function(uuid, callback) {
// Load search results into the current playlist.
djr.Player.prototype.loadSearchResults = function(hashes, replace) {
var uuid = this.curPlaylistId;
if (replace || !uuid) {
uuid = djr.generateRandomId();
}
this.curPlaylistId = uuid;
if (replace) {
var uuid = djr.generateRandomId();
this.setPlaylist(uuid, hashes);
this.setPlaylist(hashes);
} else {
this.extendPlaylist(hashes);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment