summaryrefslogtreecommitdiff
path: root/static/player.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/player.js')
-rw-r--r--static/player.js36
1 files changed, 14 insertions, 22 deletions
diff --git a/static/player.js b/static/player.js
index ce75249..c0cf6ff 100644
--- a/static/player.js
+++ b/static/player.js
@@ -19,19 +19,14 @@ function MusicListing(type, path, name, cached) {
this.a.tag = path;
this.play = function() {
- var transcode = document.getElementById('trans_enabled').checked;
- var trans_from = document.getElementById('trans_from').value;
- var trans_to = document.getElementById('trans_to').value;
- var p = path;
- if(transcode)
- p += '?decoder=' + trans_from + '&encoder=' + trans_to;
- log('playing ' + p);
- change_url('/files/' + p);
- audio.play();
+ log('playing ' + path);
+ xmlhttp = new XMLHttpRequest();
+ xmlhttp.open('GET', '/play?path=' + encodeURIComponent(path));
+ xmlhttp.send(null);
}
- this.cache = function() {
- var path = '/cache?path=' + encodeURIComponent(this.path) +
+ this.recode = function() {
+ var path = '/recode?path=' + encodeURIComponent(this.path) +
'&decoder=' + document.getElementById('trans_from').value +
'&encoder=' + document.getElementById('trans_to').value;
var a = this.a;
@@ -56,16 +51,7 @@ function MusicListing(type, path, name, cached) {
if(type == 'dir') {
list(path);
} else if(type == 'file') {
- var transcode = document.getElementById('trans_enabled').checked;
- var trans_from = document.getElementById('trans_from').value;
- var trans_to = document.getElementById('trans_to').value;
-
- var p = path;
- if(transcode) {
- ml.cache(p);
- } else {
- ml.play();
- }
+ ml.play();
}
return false;
}
@@ -163,12 +149,18 @@ function event_handler(event) {
}
}
-window.onload = function() {
+function event_open() {
+ if(source)
+ source.close();
source = new EventSource('/events');
source.onopen = function() { log('event source opened'); }
source.onmessage = event_handler;
source.onerror = function(event) { log('event source error'); }
log('event source status: ' + source.readyState);
+}
+
+window.onload = function() {
+ event_open();
audio = new Audio();
list('/');