1
0
Fork 0
oldhaven/public/javascripts/player.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-06-14 16:05:12 +00:00
var Player = {
bar_width: 330,
2011-06-14 16:05:12 +00:00
getTrackUrl: function(data) {
},
addTrack: function(artist, track, length) {
$('.playlist-tracks').append('\
<li id="i'+ Math.round(Math.random() * 999999) +'">\
<div class="item">\
<span class="title">'+ artist +' &mdash; '+ track +'</span>\
<span class="duration">'+ length +'</span>\
</div>\
</li>\
');
},
setTrack: function(obj) {
var id = $(obj).attr('id');
var query = $(obj).find('.title').html();
var length = $(obj).find('.duration').html();
$('#player .now-playing').html(query);
$('.playlist-tracks li').removeClass('now');
$('#'+ id).addClass('now');
loadTracksData(query, this.playSource);
},
playSource: function(url) {
Audio.setTrack(url);
Audio.play();
Audio.startListener();
},
updateUI: function(buffered, played) {
$('#player .loaded').width(Math.round(buffered * this.bar_width));
$('#player .played').width(Math.round(played * this.bar_width));
}
}
$('.add-album').live('click', function() {
var artist = $('.artist-info .name').html();
$(this).parent().parent().parent().find('.tracklist li').each(function(i, item){
2011-06-14 16:05:12 +00:00
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();
}
});
2011-06-14 16:05:12 +00:00
$('.playlist-tracks li').live('dblclick', function(){
Player.setTrack(this);
});
2011-06-14 16:05:12 +00:00
$(function(){
Audio.init();
});