Select Git revision
player.js 10.51 KiB
// player.js
// Player
djr.Player = function(backend, selector) {
this.backend = backend;
this.playlist = new djr.Playlist();
this.old_songs = [];
this.cur_song = null;
this.auto_extend = true;
// Setup the jPlayer interface.
this.circleplayer = new CirclePlayer(selector, {}, {
supplied: 'mp3',
solution: 'html, flash',
swfPath: '/static/js',
cssSelectorAncestor: '#cp_container',
error: djr.playerError
});
this.player = this.circleplayer.player;
this.player.bind($.jPlayer.event.ended + '.djr',
function () {djr.state.player.nextSong(); });
};
djr.Player.prototype.hideAllChunks = function() {
$('.chunk .chunk_inner').hide();
};
// Callback for removechunk click.
djr.Player.prototype.removeChunk = function(chunk_id) {
this.playlist.removeChunk(chunk_id);
$('#chunk_' + chunk_id).remove();
this.savePlaylist();
// If the playlist is now empty, switch to a new uuid.
if (this.playlist.isEmpty()) {
this.clearPlaylist();
}
};
// Remove a single song.
djr.Player.prototype.removeSong = function(song) {
$('#song_' + song).remove();
var chunk_to_remove = this.playlist.removeSong(song);
this.savePlaylist();
if (chunk_to_remove > 0) {
$('#chunk_' + chunk_to_remove).remove();
}
};
// Save the current playlist.
djr.Player.prototype.savePlaylist = function() {
this.backend.savePlaylist(this.playlist.uuid, '', this.playlist.allSongs());
};
// Save the current playlist.
djr.Player.prototype.savePlaylistWithTitle = function(title) {
this.backend.savePlaylist(djr.generateRandomId(), title, this.playlist.allSongs());
// Merge all existing chunks into one, named as the playlist.
this.mergePlaylistChunks('playlist: ' + title);
};
// Completely clear out the current playlist, and replace it with
// a new empty one.
djr.Player.prototype.clearPlaylist = function() {
this.playlist = new djr.Playlist();
$('#playlistDiv').empty();
djr.debug('new playlist: ' + this.playlist.uuid);
};