upgrades and whatnot

This commit is contained in:
GM-Script-Writer-62850 2014-06-01 18:51:19 -04:00
parent b63a787981
commit 86a9fd3bee
2 changed files with 24 additions and 6 deletions

View file

@ -1,3 +1,4 @@
"use strict";
var music=Array(), var music=Array(),
track,audio,pic,title,shuffle,repeat,err,playlist,offset; track,audio,pic,title,shuffle,repeat,err,playlist,offset;
function getId(id){ function getId(id){
@ -11,7 +12,7 @@ function randInt(min,max){
return rand; return rand;
} }
function sendEvt(element,event){ function sendEvt(element,event){
evt = document.createEvent("HTMLEvents"); var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); evt.initEvent(event, true, true );
return !element.dispatchEvent(evt); return !element.dispatchEvent(evt);
} }
@ -21,6 +22,7 @@ function extToMime(ext){
case "ogg":return "audio/ogg"; case "ogg":return "audio/ogg";
case "aac":return "audio/aac"; case "aac":return "audio/aac";
case "wav":return "audio/wave"; case "wav":return "audio/wave";
case "webm":return "audio/webm";
default: "audio/"+ext; default: "audio/"+ext;
} }
} }
@ -125,7 +127,8 @@ function init(){
offset=getId('player').offsetHeight+32; offset=getId('player').offsetHeight+32;
playlist=getId('playlist'); playlist=getId('playlist');
playlist.appendChild(ul); playlist.appendChild(ul);
populateList(libary,ul,'library/');// Folder containing music sendEvt(window,'resize');
populateList(library['music'],ul,library['path']);
config=config!=null?JSON.parse(config):{// Default player settings config=config!=null?JSON.parse(config):{// Default player settings
"volume":.25, "volume":.25,
"track":0, "track":0,
@ -147,7 +150,6 @@ function init(){
next=0; next=0;
} }
} }
sendEvt(music[next],'click'); sendEvt(music[next],'click');
},false); },false);
getId('next').addEventListener("click",function(){ getId('next').addEventListener("click",function(){
@ -192,6 +194,19 @@ function init(){
"repeat":repeat.checked===true "repeat":repeat.checked===true
})); }));
} }
document.addEventListener('keyup',function(event){// keyboard shortcuts
switch(event.which){
case 32:audio[audio.paused?'play':'pause']();return;// spacebar
case 107:audio.volume=audio.volume+.1>1?1:audio.volume+.1;return;// + (num pad)
case 109:audio.volume=audio.volume-.1<0?0:audio.volume-.1;return;// - (num pad)
case 37:getId('back').click();return;// left arrow
case 39:getId('next').click();return;// right arrow
case 38:audio.currentTime+=5;return;// up arrow
case 40:audio.currentTime-=5;return;// down arrow
case 83:shuffle.checked=!shuffle.checked;return;// s
case 82:repeat.checked=!repeat.checked;return;// r
}
},false);
} }
window.onresize=function(){ window.onresize=function(){
playlist.style.maxHeight=window.innerHeight-offset+'px'; playlist.style.maxHeight=window.innerHeight-offset+'px';

View file

@ -1,5 +1,8 @@
<?php header("content-type: application/javascript"); ?> <?php
var libary=<?php $F='library';// Name of folder containing music
header("content-type: application/javascript");
?>
var library=<?php
function tree($dir,$depth){ function tree($dir,$depth){
$json=new stdClass(); $json=new stdClass();
$scan=scandir($dir); $scan=scandir($dir);
@ -25,5 +28,5 @@ var libary=<?php
} }
return $json; return $json;
} }
echo json_encode(tree('library',0)); echo json_encode(array('music'=>tree($F,0),'path'=>"$F/"));
?> ?>