Select Git revision
-
Robert J. Newmark authored
Never Most Random and Last has 5 or 25 results
Robert J. Newmark authoredNever Most Random and Last has 5 or 25 results
player.js 11.92 KiB
// player.js
// Player
djr.Player = function(backend, selector) {
this.backend = backend;
this.player = $(selector);
this.playlist = new djr.Playlist();
this.old_songs = [];
this.cur_song = null;
// Setup the jPlayer interface.
this.player.jPlayer({
swfPath: '/static/js',
ready: function() {
djr.debug('player ready');
}
});
this.player.bind($.jPlayer.event.ended + '.djr',
function () {djr.state.player.nextSong(); });
this.player.bind($.jPlayer.event.error + '.djr',
function() {djr.state.player.reportError(); });
};
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);
this.savePlaylist();
$('#chunk_' + chunk_id).remove();
};
// 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());
};
// 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();
};
// Merge all chunks into a single one.
djr.Player.prototype.mergePlaylistChunks = function() {
// Reduce the playlist to a single chunk.
this.playlist = this.playlist.merge();
// Shuffle the HTML data around (so we don't have to necessarily
// fetch it again from the server). This is done in a few steps:
// 1) Copy all .chunk_inner data in a temp
var plhtml = [];
$('.chunk .chunk_inner').each(function(idx) {
plhtml.push($(this).html());
});