2011-07-26 18:04:57 +04:00
|
|
|
var PlayList={
|
|
|
|
urlBase:OC.linkTo('media','ajax/api.php')+'?action=play&path=',
|
|
|
|
current:-1,
|
|
|
|
items:[],
|
|
|
|
player:null,
|
2011-08-01 18:43:02 +04:00
|
|
|
volume:0.8,
|
2011-08-04 03:19:21 +04:00
|
|
|
active:false,
|
2011-07-26 18:04:57 +04:00
|
|
|
next:function(){
|
2011-08-25 22:37:51 +04:00
|
|
|
var items=PlayList.items;
|
2011-07-26 18:04:57 +04:00
|
|
|
var next=PlayList.current+1;
|
2011-08-12 14:34:02 +04:00
|
|
|
if(next>=items.length){
|
2011-07-26 18:04:57 +04:00
|
|
|
next=0;
|
|
|
|
}
|
|
|
|
PlayList.play(next);
|
2011-07-30 01:53:22 +04:00
|
|
|
PlayList.render();
|
2011-07-26 18:04:57 +04:00
|
|
|
},
|
|
|
|
previous:function(){
|
2011-08-25 22:37:51 +04:00
|
|
|
var items=PlayList.items;
|
2011-07-26 18:04:57 +04:00
|
|
|
var next=PlayList.current-1;
|
|
|
|
if(next<0){
|
2011-08-12 14:34:02 +04:00
|
|
|
next=items.length-1;
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
|
|
|
PlayList.play(next);
|
2011-07-30 01:53:22 +04:00
|
|
|
PlayList.render();
|
2011-07-26 18:04:57 +04:00
|
|
|
},
|
2011-08-01 18:43:02 +04:00
|
|
|
play:function(index,time,ready){
|
2011-08-25 22:37:51 +04:00
|
|
|
var items=PlayList.items;
|
2011-07-26 18:04:57 +04:00
|
|
|
if(index==null){
|
|
|
|
index=PlayList.current;
|
|
|
|
}
|
2011-09-29 00:20:26 +04:00
|
|
|
PlayList.save();
|
2011-08-12 14:34:02 +04:00
|
|
|
if(index>-1 && index<items.length){
|
2011-07-26 18:04:57 +04:00
|
|
|
PlayList.current=index;
|
|
|
|
if(PlayList.player){
|
2011-08-12 14:34:02 +04:00
|
|
|
if(PlayList.player.data('jPlayer').options.supplied!=items[index].type){//the the audio type changes we need to reinitialize jplayer
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.player.jPlayer("play",time);
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_time',time);
|
2011-07-26 18:04:57 +04:00
|
|
|
PlayList.player.jPlayer("destroy");
|
2011-09-29 00:20:26 +04:00
|
|
|
// PlayList.save(); // so that the init don't lose the playlist
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.init(items[index].type,null); // init calls load that calls play
|
2011-07-26 18:04:57 +04:00
|
|
|
}else{
|
2011-08-12 14:34:02 +04:00
|
|
|
PlayList.player.jPlayer("setMedia", items[PlayList.current]);
|
2011-09-29 00:20:26 +04:00
|
|
|
$(".jp-current-song").text(items[PlayList.current].name);
|
2011-08-12 14:34:02 +04:00
|
|
|
items[index].playcount++;
|
2011-08-01 18:43:02 +04:00
|
|
|
PlayList.player.jPlayer("play",time);
|
2011-08-01 03:56:45 +04:00
|
|
|
if(index>0){
|
2011-08-01 03:25:34 +04:00
|
|
|
var previous=index-1;
|
|
|
|
}else{
|
2011-08-12 14:34:02 +04:00
|
|
|
var previous=items.length-1;
|
2011-08-01 03:25:34 +04:00
|
|
|
}
|
2011-08-12 14:34:02 +04:00
|
|
|
if(index+1<items.length){
|
2011-08-01 03:25:34 +04:00
|
|
|
var next=index+1;
|
|
|
|
}else{
|
|
|
|
var next=0;
|
|
|
|
}
|
2011-08-12 14:34:02 +04:00
|
|
|
$('.jp-next').attr('title',items[next].name);
|
|
|
|
$('.jp-previous').attr('title',items[previous].name);
|
2011-08-01 03:12:28 +04:00
|
|
|
if (typeof Collection !== 'undefined') {
|
2011-07-30 02:21:24 +04:00
|
|
|
Collection.registerPlay();
|
|
|
|
}
|
2011-09-29 00:20:26 +04:00
|
|
|
PlayList.render();
|
2011-08-01 18:19:51 +04:00
|
|
|
if(ready){
|
|
|
|
ready();
|
|
|
|
}
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
|
|
|
}else{
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_time',time);
|
|
|
|
OC.localStorage.setItem('playlist_playing',true);
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.init(items[index].type,null); // init calls load that calls play
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
|
|
|
}
|
2011-09-29 00:20:26 +04:00
|
|
|
$(".song").removeClass("collection_playing");
|
|
|
|
$(".jp-playlist-" + index).addClass("collection_playing");
|
2011-07-26 18:04:57 +04:00
|
|
|
},
|
|
|
|
init:function(type,ready){
|
|
|
|
if(!PlayList.player){
|
|
|
|
$(".jp-previous").click(function() {
|
|
|
|
PlayList.previous();
|
|
|
|
$(this).blur();
|
|
|
|
PlayList.render();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$(".jp-next").click(function() {
|
|
|
|
PlayList.next();
|
|
|
|
$(this).blur();
|
|
|
|
PlayList.render();
|
|
|
|
return false;
|
|
|
|
});
|
2011-09-29 00:20:26 +04:00
|
|
|
PlayList.player=$('#jp-player');
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
|
|
|
$(PlayList.player).jPlayer({
|
|
|
|
ended:PlayList.next,
|
2011-08-01 18:19:51 +04:00
|
|
|
pause:function(){
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_playing',false);
|
2012-01-08 20:00:30 +04:00
|
|
|
document.title = "ownCloud";
|
2011-08-01 18:19:51 +04:00
|
|
|
},
|
2012-01-08 20:00:30 +04:00
|
|
|
play:function(event){
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_playing',true);
|
2012-01-08 20:00:30 +04:00
|
|
|
document.title = "\u25b8 " + event.jPlayer.status.media.name + " - " + event.jPlayer.status.media.artist + " - ownCloud";
|
2011-08-01 18:19:51 +04:00
|
|
|
},
|
2011-07-26 18:04:57 +04:00
|
|
|
supplied:type,
|
|
|
|
ready:function(){
|
2011-08-01 03:12:28 +04:00
|
|
|
PlayList.load();
|
2011-07-26 18:04:57 +04:00
|
|
|
if(ready){
|
|
|
|
ready();
|
|
|
|
}
|
|
|
|
},
|
2011-08-01 18:43:02 +04:00
|
|
|
volume:PlayList.volume,
|
2011-09-29 00:20:26 +04:00
|
|
|
cssSelectorAncestor:'.player-controls',
|
2011-07-27 18:38:23 +04:00
|
|
|
swfPath:OC.linkTo('media','js'),
|
2011-07-26 18:04:57 +04:00
|
|
|
});
|
|
|
|
},
|
2011-08-25 22:37:51 +04:00
|
|
|
add:function(song,dontReset){
|
2011-08-12 14:34:02 +04:00
|
|
|
if(!dontReset){
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.items=[];//clear the playlist
|
2011-08-12 14:34:02 +04:00
|
|
|
}
|
2011-07-30 01:53:22 +04:00
|
|
|
if(!song){
|
|
|
|
return;
|
|
|
|
}
|
2011-07-26 18:04:57 +04:00
|
|
|
if(song.substr){//we are passed a string, asume it's a url to a song
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.addFile(song,true);
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
|
|
|
if(song.albums){//a artist object was passed, add all albums inside it
|
|
|
|
$.each(song.albums,function(index,album){
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.add(album,true);
|
2011-07-26 18:04:57 +04:00
|
|
|
});
|
2011-08-25 22:37:51 +04:00
|
|
|
} else if(song.songs){//a album object was passed, add all songs inside it
|
2011-07-26 18:04:57 +04:00
|
|
|
$.each(song.songs,function(index,song){
|
2011-08-25 22:37:51 +04:00
|
|
|
PlayList.add(song,true);
|
2011-07-26 18:04:57 +04:00
|
|
|
});
|
|
|
|
}
|
2011-08-21 17:28:20 +04:00
|
|
|
if(song.path){
|
|
|
|
var type=musicTypeFromFile(song.path);
|
|
|
|
var item={name:song.name,type:type,artist:song.artist,album:song.album,length:song.length,playcount:song.playCount};
|
|
|
|
item[type]=PlayList.urlBase+encodeURIComponent(song.path);
|
2011-09-29 00:20:26 +04:00
|
|
|
PlayList.items.push(item);
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
addFile:function(path){
|
|
|
|
var type=musicTypeFromFile(path);
|
2011-08-01 02:32:44 +04:00
|
|
|
var item={name:'unknown',artist:'unknown',album:'unknwon',type:type};
|
|
|
|
$.getJSON(OC.filePath('media','ajax','api.php')+'?action=get_path_info&path='+encodeURIComponent(path),function(song){
|
|
|
|
item.name=song.song_name;
|
|
|
|
item.artist=song.artist;
|
|
|
|
item.album=song.album;
|
|
|
|
});
|
2011-07-26 18:04:57 +04:00
|
|
|
item[type]=PlayList.urlBase+encodeURIComponent(path);
|
|
|
|
PlayList.items.push(item);
|
|
|
|
},
|
2011-07-30 01:53:22 +04:00
|
|
|
remove:function(index){
|
|
|
|
PlayList.items.splice(index,1);
|
|
|
|
PlayList.render();
|
|
|
|
},
|
2011-07-31 03:25:33 +04:00
|
|
|
render:function(){},
|
|
|
|
playing:function(){
|
|
|
|
if(!PlayList.player){
|
|
|
|
return false;
|
|
|
|
}else{
|
|
|
|
return !PlayList.player.data("jPlayer").status.paused;
|
|
|
|
}
|
2011-08-01 03:12:28 +04:00
|
|
|
},
|
|
|
|
save:function(){
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_items',PlayList.items);
|
|
|
|
OC.localStorage.setItem('playlist_current',PlayList.current);
|
|
|
|
if(PlayList.player) {
|
|
|
|
if(PlayList.player.data('jPlayer')) {
|
|
|
|
var time=Math.round(PlayList.player.data('jPlayer').status.currentTime);
|
|
|
|
OC.localStorage.setItem('playlist_time',time);
|
|
|
|
var volume=PlayList.player.data('jPlayer').options.volume*100;
|
|
|
|
OC.localStorage.setItem('playlist_volume',volume);
|
2011-09-29 00:20:26 +04:00
|
|
|
}
|
2011-08-01 03:12:28 +04:00
|
|
|
}
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_active',true);
|
2011-08-01 03:12:28 +04:00
|
|
|
},
|
|
|
|
load:function(){
|
2012-01-15 22:25:55 +04:00
|
|
|
PlayList.active=true;
|
|
|
|
OC.localStorage.setItem('playlist_active',true);
|
|
|
|
if(OC.localStorage.hasItem('playlist_items')){
|
|
|
|
PlayList.items=OC.localStorage.getItem('playlist_items');
|
|
|
|
if(PlayList.items && PlayList.items.length>0){
|
|
|
|
PlayList.current=OC.localStorage.getItem('playlist_current');
|
|
|
|
var time=OC.localStorage.getItem('playlist_time');
|
|
|
|
if(OC.localStorage.hasItem('playlist_volume')){
|
|
|
|
var volume=OC.localStorage.getItem('playlist_volume');
|
|
|
|
PlayList.volume=volume/100;
|
|
|
|
$('.jp-volume-bar-value').css('width',volume+'%');
|
|
|
|
if(PlayList.player.data('jPlayer')){
|
|
|
|
PlayList.player.jPlayer("option",'volume',volume/100);
|
2011-08-03 16:23:35 +04:00
|
|
|
}
|
2011-08-01 18:43:02 +04:00
|
|
|
}
|
2012-01-15 22:25:55 +04:00
|
|
|
if(OC.localStorage.getItem('playlist_playing')){
|
|
|
|
PlayList.play(null,time);
|
|
|
|
}else{
|
|
|
|
PlayList.play(null,time,function(){
|
|
|
|
PlayList.player.jPlayer("pause");
|
|
|
|
});
|
|
|
|
}
|
|
|
|
PlayList.render();
|
2011-08-01 03:12:28 +04:00
|
|
|
}
|
|
|
|
}
|
2011-07-31 03:25:33 +04:00
|
|
|
}
|
2011-07-26 18:04:57 +04:00
|
|
|
}
|
2011-08-04 03:19:21 +04:00
|
|
|
|
|
|
|
$(document).ready(function(){
|
|
|
|
$(window).bind('beforeunload', function (){
|
|
|
|
PlayList.save();
|
2011-09-29 02:48:45 +04:00
|
|
|
if(PlayList.active){
|
2012-01-15 22:25:55 +04:00
|
|
|
OC.localStorage.setItem('playlist_active',false);
|
2011-09-29 02:48:45 +04:00
|
|
|
}
|
2011-08-04 03:19:21 +04:00
|
|
|
});
|
2011-08-13 18:34:40 +04:00
|
|
|
|
|
|
|
$('jp-previous').tipsy({gravity:'n', fade:true, live:true});
|
|
|
|
$('jp-next').tipsy({gravity:'n', fade:true, live:true});
|
2011-08-04 03:19:21 +04:00
|
|
|
})
|