var Player = { bar_width: 330, getTrackUrl: function(data) { }, addTrack: function(artist, track, length) { $('.playlist-tracks').append('\
  • \
    \
    \ '+ artist +' — '+ track +'\ '+ length +'\
    remove
    \
    \
  • \ '); $('#playlist').html($('.playlist-tracks')).scrollbar(); $('.playlist-tracks').sortable(); }, setTrack: function(id) {console.log(1); var $obj = $('#i'+ id); var query = $obj.find('.title').text(); var length = $obj.find('.duration').text(); var tmp = query.split(' — '); $('#player .now-playing').html(query); $('.playlist-tracks li').removeClass('now'); $obj.addClass('now'); $('#player .loaded, #player .played').width(0); loadTracksData(tmp[0], tmp[1], length, Player.playSource); }, playSource: function(url) { var id = $('.playlist-tracks .now').attr('id').split('i')[1]; Audio.pause(); Audio.rewind(); Audio.addTrack(id, url); Audio.setTrack(id); Audio.play(); Audio.startListener(); }, nextTrack: function() { if (true) { // Shuffle off if ($('.playlist-tracks .now').next().length == 0 && true) { // Last track in the playlist and repeat is on return $('.playlist-tracks li').first().attr('id').split('i')[1]; } else { return $('.playlist-tracks .now').next().attr('id').split('i')[1]; } } }, prevTrack: function() { if (true) { // Shuffle off if ($('.playlist-tracks .now').prev().length == 0 && true) { // First track in the playlist return $('.playlist-tracks li').last().attr('id').split('i')[1]; } else { return $('.playlist-tracks .now').prev().attr('id').split('i')[1]; } } }, updateUI: function(buffered, played) { $('#player .loaded').width(Math.round(buffered * this.bar_width)); $('#player .played').width(Math.round(played * this.bar_width)); if (played == 1) { Audio.killListener(); Player.setTrack(Player.nextTrack()); } }, reset: function() { Audio.pause(); $('#player .loaded, #player .played').width(0); $('#player .now-playing').text('Select track'); } } $('#player .controls .prev').live('click', function(){ Player.setTrack(Player.prevTrack()); }); $('#player .controls .next').live('click', function(){ Player.setTrack(Player.nextTrack()); }); $('.add-album').live('click', function() { var artist = $('.artist-info .name').html(); $(this).parent().parent().parent().find('.tracklist li').each(function(i, item){ var track_name = $(item).find('.trackname').html(); var length = $(item).find('.length').html(); Player.addTrack(artist, track_name, length); }); }) $('.add-track').live('click', function(){ var artist = $('.artist-info .name').html(); var track_name = $(this).parent().find('.trackname').html(); var length = $(this).parent().find('.length').html(); Player.addTrack(artist, track_name, length); }); $('.tracklist li').live('mouseover mouseout', function(e){ if (e.type == 'mouseover') { $(this).find('.add-track').show(); } else { $(this).find('.add-track').hide(); } }); $('.playlist-tracks li .fade, .playlist-tracks li .duration, .playlist-tracks li .remove').live('mouseover mouseout', function(e){ if (e.type == 'mouseover') { $(this).parent().find('.duration').hide(); $(this).parent().find('.remove').show(); } else { $(this).parent().find('.remove').hide(); $(this).parent().find('.duration').show(); } }); $('.playlist-tracks li .remove').live('click', function(){ var $li = $(this).parent().parent(); if ($li.hasClass('now')) { Player.reset(); } $li.remove(); }); $('.playlist-tracks li').live('dblclick', function(){ Player.setTrack($(this).attr('id').split('i')[1]); }); $('#player .progress').live('click', function(e){ Audio.skipToPercent(e.offsetX / Player.bar_width); });