118 lines
3.2 KiB
JavaScript
118 lines
3.2 KiB
JavaScript
var Player = {
|
|
|
|
bar_width: 330,
|
|
|
|
getTrackUrl: function(data) {
|
|
|
|
},
|
|
|
|
addTrack: function(artist, track, length) {
|
|
$('.playlist-tracks').append('\
|
|
<li id="i'+ Math.round(Math.random() * 999999) +'">\
|
|
<div class="item">\
|
|
<div class="fade"></div>\
|
|
<span class="title">'+ artist +' — '+ track +'</span>\
|
|
<span class="duration">'+ length +'</span>\
|
|
</div>\
|
|
</li>\
|
|
');
|
|
|
|
$('#playlist').html($('.playlist-tracks')).scrollbar();
|
|
},
|
|
|
|
setTrack: function(obj) {
|
|
if (typeof obj == 'string') {
|
|
var id = obj;
|
|
obj = $('#i'+ obj);
|
|
} else {
|
|
var id = $(obj).attr('id').split('i')[1];
|
|
}
|
|
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');
|
|
$('#i'+ id).addClass('now');
|
|
|
|
loadTracksData(tmp[0], tmp[1], length, this.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());
|
|
}
|
|
}
|
|
}
|
|
|
|
$('#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').live('dblclick', function(){
|
|
Player.setTrack(this);
|
|
});
|
|
|
|
$('#player .progress').live('click', function(e){
|
|
Audio.skipToPercent(e.offsetX / Player.bar_width);
|
|
}); |