From a3e86f3be768c8fa1fc2af12d5e5d66d9d9b82e8 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Tue, 16 Aug 2011 14:49:40 +0200 Subject: Implemented basic cuesheet support, some playlist fixes. --- static/player.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'static/player.js') diff --git a/static/player.js b/static/player.js index 90acf0b..b358eb5 100644 --- a/static/player.js +++ b/static/player.js @@ -12,22 +12,28 @@ for(var i = 0; i < cache_images.length; i++) { img.src = '/static/icons/' + cache_images[i]; } -function MusicListing(type, path, name, cached) { +function MusicListing(type, path, name, track, cached) { this.type = type; this.path = path; this.name = name ? name : path.split('/').pop(); + this.track = track; this.a = document.createElement('a'); this.a.ml = this; this.play = function() { + var path = '/play?path=' + encodeURIComponent(this.path); + if(this.track) + path += '&track=' + this.track; log('playing ' + path); xmlhttp = new XMLHttpRequest(); - xmlhttp.open('GET', '/play?path=' + encodeURIComponent(path)); + xmlhttp.open('GET', path); xmlhttp.send(null); } this.recode = function() { var path = '/recode?path=' + encodeURIComponent(this.path); + if(this.track) + path += '&track=' + this.track; var a = this.a; var ml = this; var xmlhttp = new XMLHttpRequest(); @@ -43,7 +49,10 @@ function MusicListing(type, path, name, cached) { className += ' file-cached' a.setAttribute('class', className); a.setAttribute('href', '#'); - a.appendChild(document.createTextNode(this.name)); + var name = this.name; + if(this.track) + name += ' (track ' + this.track + ')'; + a.appendChild(document.createTextNode(name)); var ml = this; a.onclick = function() { @@ -104,9 +113,10 @@ function list(root) { for(var i = 0; i < json.length; i++) { var type = json[i]["type"]; var path = json[i]["name"]; + var track = json[i]["track"]; var name = path.substring(path.lastIndexOf('/')+1); var cached = type == "file" ? json[i]["cached"] : false; - var l = new MusicListing(type, path, name, cached); + var l = new MusicListing(type, path, name, track, cached); output_link(l); } } @@ -131,11 +141,11 @@ function add_directory() { var source = null; -function get_a(path) { +function get_a(path, track) { var as = document.getElementById('song-links').getElementsByTagName('a'); for(var i = 0; i < as.length; i++) { var a = as[i]; - if(a.ml.path == path) + if(a.ml.path == path && (!track || track == a.ml.track)) return a; } } @@ -146,12 +156,16 @@ function event_handler(event) { case 'cached': case 'recoding': log('[' + data['type'] + '] ' + data['path']); + var track = null; + if('track' in data) + track = data['track']; + log('track: ' + track); // update directory browser - var a = get_a(data['path']); + var a = get_a(data['path'], track); if(a) a.setAttribute('class', 'file file-' + data['type']); // update song queue - var li = playlist.get(data['path']); + var li = playlist.get(data['path'], track); if(li) { a = li.getElementsByTagName('a')[0]; if(data['type'] == 'cached') { -- cgit v1.2.3