Skip to content
Browse files

player improvements

  • Loading branch information...
1 parent 4dd1e5a commit e294af463e848603e6e0ebf4ff51b0ecc8f133ea @RJ committed Dec 26, 2009
Showing with 383 additions and 196 deletions.
  1. +6 −1 WebkitApi.cpp
  2. +1 −0 WebkitApi.h
  3. +3 −1 mainwindow.cpp
  4. +0 −3 mainwindow.h
  5. +2 −1 www/index.html
  6. +216 −157 www/player/scripts/player.js
  7. +14 −0 www/player/stylesheets/player.css
  8. +141 −33 www/test.html
View
7 WebkitApi.cpp
@@ -29,7 +29,7 @@ void WebkitApi::attachObject()
void WebkitApi::emitTick(qint64 i64, qint64 i64rem)
{
int el = i64 / 1000;
- int rem = i64rem / 1000;
+ int rem = i64rem>0?(i64rem / 1000):i64rem;
emit(elapsed(el, rem));
}
@@ -78,3 +78,8 @@ void WebkitApi::stop()
{
emit(stopRequested());
}
+
+void WebkitApi::log(QString s)
+{
+ qDebug() << s;
+}
View
1 WebkitApi.h
@@ -35,6 +35,7 @@ public slots:
void play(QString);
void stop();
void setWindowTitle(QString);
+ void log(QString);
private slots:
void attachObject();
View
4 mainwindow.cpp
@@ -158,6 +158,7 @@ void MainWindow::stop()
void MainWindow::bufferPercent(int pc)
{
+ qDebug() << "BufferPercent: " << pc;
// perhaps some logic that decides if we should abort due to slowness?
webkitApi->emitBufferPercent(pc);
}
@@ -197,13 +198,14 @@ void MainWindow::stateChanged(Phonon::State newState, Phonon::State /* oldState
void MainWindow::sourceChanged(const Phonon::MediaSource & source)
{
- log("Source changed: " + source.url().toString());
+ qDebug() << "Source changed: " + source.url().toString();
// musicTable->selectRow(sources.indexOf(source));
// timeLcd->display("00:00");
}
void MainWindow::metaStateChanged(Phonon::State newState, Phonon::State /* oldState */)
{
+ qDebug() << "Metastate changed to " << newState;
if (newState == Phonon::ErrorState) {
log("ERROR opening files: " + metaInformationResolver->errorString());
//QMessageBox::warning(this, tr("Error opening files"),
View
3 mainwindow.h
@@ -13,7 +13,6 @@
#include <QEvent>
#include "WebkitApi.h"
-#include "jabber.h"
class Webpage : public QWebPage
{
@@ -52,8 +51,6 @@ private slots:
private:
- Jabber * jabber;
-
WebkitApi * webkitApi;
QWebView * webView;
QPushButton *playurlBtn;
View
3 www/index.html
@@ -44,7 +44,7 @@
$('bufferpc').innerHTML = "Buffering: " + pc +"%";
});
- // 0-100, new volume setting
+ // 0-100, new volume setting (could have been changed via dbus - update gui)
MK.volumeChanged.connect(function(v){
mk_log('volume set to ' + v);
});
@@ -79,5 +79,6 @@
<a href="test.html">test page</a>
<a href="playdar.html">playdar test page</a>
<a href="playdar2.html">playdar2 test page</a>
+<a href="player/index.html">/player/</a>
</body>
</html>
View
373 www/player/scripts/player.js
@@ -1,94 +1,16 @@
-/*
-function arraySum(a) {
- var sum = 0
- $.each(a,function(i) {
- sum += a[i];
- });
- return sum;
-}
-
-
-Playlist = function(){}
-Playlist.prototype = {
- tracks: [],
- trackids: {},
- currentid: false,
- id: "playlist0001",
-
- init: function(){
- var self=this;
- $('#playlist')
- .clone()
- .attr('id',"list-" + this.id)
- .appendTo("#lists")
- .hide();
- this.dom = $("#lists > div:last"); // a bit ugly
- this.list = $("tbody", this.dom);
- this.colWidths = new Array(20,250,130,50,100); // default col widths
- // header colWidths
- $("table.list-header th",this.dom).each(function(i) {
- $(this).width(self.colWidths[i]);
- });
-
-
- },
-
- addTrack: function(t){
- var self = this;
- if(!t.qid) t.sid=Playdar.Util.generate_uuid();
- this.tracks[this.tracks.length] = t;
- //this.trackqids[t.qid]=this.tracks.length-1;
- $('#playlist-row table tr')
- .clone()
- //.css("width",SC.arraySum(self.colWidths)+7*7)
- .dblclick(function() {
- //self.player.currentPlaylist = self;
- // find out at which position we are at in the playlist, and store that as the currentPos
- //self.currentPos = $(this).parents("tbody").find("tr").index(this);
- $(this).addClass("selected");
- self.loadTrack(self.currentPos);
- })
- .find("td:nth-child(1)").css("width",self.colWidths[0]).end()
- .find("td:nth-child(2)").css("width",self.colWidths[1]).text(t.track).end()
- .find("td:nth-child(3)").css("width",self.colWidths[2]).text(t.artist).end()
- .find("td:nth-child(4)").css("width",self.colWidths[3]).text(Playdar.Util.mmss(t.duration)).end()
- .find("td:nth-child(5)").css("width",self.colWidths[4]).text("???").end()
- .end()
- .appendTo(this.list);
-
- return t.qid;
- },
- resolveAll: function(){
- for (var i=0;i<this.tracks.length;i++)
- {
- var trk = this.tracks[i];
- Playdar.client.resolve(trk.artist, trk.track, trk.sid);
- $('#'+trk.qid).addClass('resolving');
- }
- }
-};
-
-var fakelist = new Playlist;
-fakelist.addTrack({ 'track':'Some track title',
- 'artist': 'Some artistname',
- 'sid': '9437ED1F-FD2B-4A80-8891-58666AA1CAB3',
- 'duration' : 200
- });
-fakelist.addTrack({ 'track':'Some Other track title',
- 'artist': 'Some OTHER artistname',
- 'sid': '9437ED1F-FD2B-4A80-8891-58666AA1CAB3',
- 'duration' : 234
- });
-*/
Player = function(){}
Player.prototype = {
isPlaying: false,
currentTrack : {},
go: function() {
+ Playdar.MAX_CONCURRENT_RESOLUTIONS = 15;
Playdar.USE_JSONP=false;
Playdar.USE_STATUS_BAR=false;
+ Playdar.USE_SCROBBLER = false;
+ Playdar.MAX_POLLS = 20;
+
Playdar.setupClient({
onAuth: function () {
p.initialize();
@@ -111,7 +33,7 @@ Player.prototype = {
this.playButton.click(function() {
self.togglePlay();
});
-
+
sidebarWidth = 220;
$("#sidebar").width(sidebarWidth);
@@ -136,9 +58,13 @@ Player.prototype = {
}
});
- $('#next').click(function() {
- alert('next');
- });
+ $('#next')
+ .click(function() {
+ pl.playNext();
+ })
+ .dblclick(function() {
+ pl.playAlternateOrNext();
+ });
$('#prev').click(function() {
alert('prev');
@@ -158,17 +84,9 @@ Player.prototype = {
});
$('#loop').click(function(){
- var track = { 'track':'Some track title',
- 'artist': 'Some artistname',
- 'sid': '9437ED1F-FD2B-4A80-8891-58666AA1CAB3',
- 'duration' : 200
- };
- self.play(track);
+ p.play({'artist':'Mokele', 'track':'Hiding in your insides', 'url':'http://www.playdar.org/hiding.mp3'}, 'http://www.playdar.org/hiding.mp3');
});
- $('#rand').click(function(){
- self.switchPlaylist(fakeplaylist);
- });
this.playlists = {};
// Wire up events from musickit container:
@@ -177,24 +95,42 @@ Player.prototype = {
MK.stateChange.connect(function(state){
this.laststate = state;
MK.setWindowTitle(this.laststate);
+ MK.log('State: ' + state + ' isPlaying: ' + self.isPlaying);
switch(this.laststate)
{
case 'stopped':
self.trackEnded();
+ //pl.playNext();
break;
case 'playing':
self.trackStarted(self.currentTrack);
break;
+ case 'error':
+ case 'fatalerror':
+ if(self.isPlaying)
+ {
+ pl.playAlternateOrNext();
+ }
}
});
MK.elapsed.connect(function(elapsed, remaining){
- $('#position').html(Playdar.Util.mmss(elapsed));
- $('#duration').html(Playdar.Util.mmss(remaining));
- //MK.setWindowTitle(elapsed + '/' + remaining);
- var val = 100*elapsed/(elapsed+remaining);
- $('#elapsed').css('width', val+'%');
- //if($('#loaded').css('width') < (val+'%')) $('#loaded').css('width', val+'%');
+ MK.log('elapsed js ping, remaining: ' + remaining);
+ var elapsedStr = Playdar.Util.mmss(elapsed);
+ var durationStr;
+ var widpc;
+ if( remaining == -1 ) // unknown stream length
+ {
+ durationStr = Playdar.Util.mmss(self.currentTrack.duration) + ' ?';
+ widpc = 100*elapsed/(self.currentTrack.duration+0.00001);
+ } else {
+ durationStr = Playdar.Util.mmss(remaining+elapsed);
+ widpc = 100*elapsed/(elapsed+remaining+0.000001);
+ }
+ if(widpc>100) widpc=100;
+ $('#position').html(elapsedStr);
+ $('#duration').html(durationStr);
+ $('#elapsed').css('width', widpc+'%');
});
MK.bufferPercent.connect(function(pc){
@@ -210,16 +146,16 @@ Player.prototype = {
},
playdarResult: function(response, lastPoll){
-
+ pl.addResults(response.qid, response.results, lastPoll);
},
- play: function(track) {
+ play: function(track, url) {
+ MK.log('play: ' + JSON.stringify(track));
MK.stop();
var sid = track.sid;
var self = this;
- var url = "http://www.playdar.org/hiding.mp3";
- //var url = "http://localhost:60210/sid/"+sid;
self.currentTrack = track;
+ self.isPlaying = true;
MK.play(url);
},
@@ -229,6 +165,7 @@ Player.prototype = {
stop: function() {
MK.stop();
+ self.isPlaying = false;
self.trackEnded();
},
@@ -243,7 +180,7 @@ Player.prototype = {
},
trackStarted: function(track) {
- this.isPlaying = true;
+ self.isPlaying = true;
$("body").addClass("playing");
//this.loading.css('width',"100%");
$('#np').hide().html(track.artist + " - " + track.track).fadeIn();
@@ -270,79 +207,201 @@ $(document).ready(function(){
window.p = new Player();
p.go();
- $('#playlist')
+ var req = new XMLHttpRequest();
+ req.open("GET", "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", false);
+ //req.open("GET", "toptracks.xspf", false);
+ req.send("");
+ var doc = req.responseXML;//.documentElement;
+ var jspf = XSPF.toJSPF(doc);
+ window.pl = new Playlist();
+ pl.init('0001', jspf.playlist.title);
+ for(var i=0;i<jspf.playlist.track.length;i++)
+ {
+ var track = jspf.playlist.track[i].title;
+ var artist = jspf.playlist.track[i].creator;
+ var dur = parseInt(jspf.playlist.track[i].duration)/1000;
+ pl.addTrack({ 'track':track,
+ 'artist': artist,
+ 'duration': dur});
+ }
+ //alert(qid);
+});
+
+// Playlist class:
+Playlist = function(){};
+Playlist.prototype = {
+
+ init: function(plid, name){
+ var self=this;
+ this.id = plid;
+ this.name = name;
+ this.playdarResults = {};
+ this.lastQid = false;
+ this.lastResultIndex = 0;
+ $('#lists table').hide();
+ $('#playlist-table')
.clone()
- .attr('id',"pl")
- .appendTo("#lists")
- .show();
+ .attr('id',plid)
+ .appendTo("#lists");
- this.dom = $("#lists > table:last"); // a bit ugly
- //this.dom = $('pl');
- this.list = $("tbody", this.dom);
-
+ this.dom = $("#lists > table:last");
+ //this.dom = $('pl');
+ this.list = $("tbody", this.dom);
- function withinHeaderDragArea(el,e) {
- var left = e.clientX-$(el).offset().left-($(el).width()+3);
- if(left > 0 && left < 4) {
- return true;
- } else {
- return false;
- }
- }
- $("th",this.dom)
+ function withinHeaderDragArea(el,e) {
+ var left = e.clientX-$(el).offset().left-($(el).width()+3);
+ if(left > 0 && left < 4) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+ $("th",this.dom)
.mousemove(function(e) {
- if(withinHeaderDragArea(this,e)) {
- $(this).css("cursor","col-resize");
- } else {
- $(this).css("cursor","default");
- }
+ if(withinHeaderDragArea(this,e)) {
+ $(this).css("cursor","col-resize");
+ } else {
+ $(this).css("cursor","default");
+ }
})
.mousedown(function(e) {
- var $col = $(this);
- var oldColWidth = $col.width();
- var colIdx = $(this).parents("thead").find("th").index(this) + 1;
- var rowWidth = $(this).parents("tr").width();
- var $row = $(this).parents("tr");
- var $rows = $("tr",self.list);
+ var $col = $(this);
+ var oldColWidth = $col.width();
+ var colIdx = $(this).parents("thead").find("th").index(this) + 1;
+ var rowWidth = $(this).parents("tr").width();
+ var $row = $(this).parents("tr");
+ var $rows = $("tr",self.list);
- if(withinHeaderDragArea(this,e)) {
- $(document)
- .mouseup(function() {
- $(document).unbind("mousemove");
- })
- .mousemove(function(ev) {
- var colWidth = ev.clientX - $col.offset().left;
- $col.width(colWidth);
- // resize all the cells in the same col
- $("td:nth-child(" + colIdx + ")", self.list).width(colWidth);
- $row.width(rowWidth+(colWidth-oldColWidth));
- $rows.width(rowWidth+(colWidth-oldColWidth));
- });
- }
+ if(withinHeaderDragArea(this,e)) {
+ $(document)
+ .mouseup(function() {
+ $(document).unbind("mousemove");
+ })
+ .mousemove(function(ev) {
+ var colWidth = ev.clientX - $col.offset().left;
+ if(colWidth >= 10)
+ {
+ $col.width(colWidth);
+ // resize all the cells in the same col
+ $("td:nth-child(" + colIdx + ")", self.list).width(colWidth);
+ $row.width(rowWidth+(colWidth-oldColWidth));
+ $rows.width(rowWidth+(colWidth-oldColWidth));
+ }
+ });
+ }
})
.mouseup(function(e) {
- //var colIdx = $(this).parents("thead").find("th").index(this) + 1;
- //$.cookie('playlist_col_width_' + (colIdx-1),$(this).width());
+ //var colIdx = $(this).parents("thead").find("th").index(this) + 1;
+ //$.cookie('playlist_col_width_' + (colIdx-1),$(this).width());
});
-
+
+ $('<li id="'+this.id+'"><span></span>' + this.name + '</li>')
+ .appendTo('#playlists');
+ },
+ play: function(qid){
+ var res = this.playdarResults[qid];
+ if(res.length<1)
+ {
+ alert('no results');
+ }else{
+ this.lastResultIndex = 0;
+ var url = res[this.lastResultIndex].url || Playdar.client.get_stream_url(res[this.lastResultIndex].sid);
+ $('#'+qid).addClass('playing');
+ this.lastQid=qid;
+ p.play(res[this.lastResultIndex], url);
+ }
+ },
- for(var i=0;i<100;i++)
- {
+ playAlternateOrNext: function(){
+ var qid = this.lastQid;
+ var res = this.playdarResults[qid];
+ // any more sources left to try?
+ if(res.length > this.lastResultIndex+1)
+ {
+ //alert('trying alternate');
+ this.lastResultIndex++;
+ $('#'+qid+' td.alt').hide().text(res.length-(this.lastResultIndex)).fadeIn();
+ this.setStatusCell(qid, res, true, this.lastResultIndex);
+ var url = res[this.lastResultIndex].url || Playdar.client.get_stream_url(res[this.lastResultIndex].sid);
+ p.play(res[this.lastResultIndex], url);
+ }else{
+ alert('playing next, no more alts');
+ this.playNext();
+ }
+ },
+
+ playNext: function(){
+ this.lastResultIndex = 0;
+ $('#'+this.lastQid).removeClass('playing');
+ var nextTrs = $('#'+this.lastQid+' ~ tr.playable');
+ if(nextTrs.length==0)
+ {
+ alert('fin');
+ }
+ else
+ {
+ var nextQ = nextTrs[0].id;
+ //alert('next qid = ' + nextQ);
+ this.play(nextQ);
+ }
+
+ },
+
+ addTrack: function(trk){
+ if(!trk.qid) trk.qid=Playdar.Util.generate_uuid();
$('#playlist-row')
.clone()
- //.css("width",SC.arraySum(self.colWidths)+7*7)
+ .attr('id', trk.qid)
.dblclick(function() {
//self.player.currentPlaylist = self;
// find out at which position we are at in the playlist, and store that as the currentPos
//self.currentPos = $(this).parents("tbody").find("tr").index(this);
- $(this).addClass("selected");
+ //$(this).addClass("selected");
+ pl.play(trk.qid);
//self.loadTrack(self.currentPos);
})
+ .find("td.track").text(trk.track).end()
+ .find("td.artist").text(trk.artist).end()
+ .find("td.duration").text(Playdar.Util.mmss(trk.duration)).end()
+ .find("td.status").text("Searching").end()
+ .find("td.alt").text('').end()
.appendTo(this.list);
+ Playdar.client.resolve(trk.artist, trk.track, trk.album || "", trk.qid);
+ return trk.qid;
+ },
+
+ setStatusCell: function(qid, results, lastPoll, idx){
+ if(results.length < 1)
+ {
+ if(lastPoll) $('#'+qid+' td.status').html('Not found');
+ else $('#'+qid+' td.status').html( $('#'+qid+' td.status').html()+'.');
+ }
+ else
+ {
+ var pc = Math.round( (results[idx].score || 0) * 100 );
+ $('#'+qid+' td.status').html( pc + '%' + (results[idx].source?' - '+results[idx].source:'') );
+ }
+ },
+
+ addResults: function(qid, results, lastPoll){
+ this.playdarResults[qid]=results;
+ this.setStatusCell(qid, results, lastPoll, 0);
+ $('#'+qid+' td.status').click(function(){
+ pl.play(qid);
+ });
+ if(results.length)
+ {
+ if(results[0].score >= 0.8)
+ {
+ $('#'+qid).addClass('playable').removeClass('unplayable');
+ }
+ $('#'+qid+' td.alt').html( results.length );
+ }else if(lastPoll && !$('#'+qid).hasClass('playable')) $('#'+qid).addClass('unplayable');
}
-
-});
+
+};
+
View
14 www/player/stylesheets/player.css
@@ -197,11 +197,23 @@ table {
table tbody tr.selected {
background-color: rgb(63,111,211);
}
+
+ table tbody tr.playable {
+ color: darkgreen;
+ }
+
+ table tbody tr.unplayable {
+ color: rgb(200,0,0);
+ }
table tbody tr.selected td, table tbody tr.selected td a {
color: white;
}
+ table.playlist .alt { width: 30px; }
+ table.playlist .status { width: 110px; }
+ table.playlist .duration { width: 50px; }
+
/* table tbody tr:nth-child(even):hover {
background: rgba(255,255,150,0.2);
}
@@ -215,6 +227,8 @@ table {
text-decoration: underline;
}
+
+
.hidden {
display: none;
}
View
174 www/test.html
@@ -1,65 +1,173 @@
<html>
<head>
+<link href="musickit.css" media="screen" rel="stylesheet" type="text/css" />
<script src="playdar_compressed.js"></script>
+<script src="jquery-1.3.2.min.js"></script>
+<script type="text/javascript">
+$(document).ready(function(){
+ // i: seconds played so far, emitted every second
+ MK.elapsed.connect(function(elapsed, remaining){
+ $('#np_elapsed').innerHTML = Playdar.Util.mmss(elapsed);
+ $('#np_remaining').innerHTML = '-'+Playdar.Util.mmss(remaining);
+ });
+
+ // one of: playing stopped paused buffering loading
+ MK.stateChange.connect(function(state){
+ MK.setWindowTitle(state);
+ /*
+ switch(state)
+ {
+ case 'stopped':
+ $('#np_artist').innerHTML = '';
+ $('#np_track').innerHTML = '';
+ $('#np_elapsed').innerHTML = '00:00';
+ $('#np_remaining').innerHTML = '00:00';
+ break;
+ }
+ */
+ });
+
+ // if there's any buffering, pc: 0-100 % of stream loaded.
+ MK.bufferPercent.connect(function(pc){
+ MK.setWindowTitle("Buffering: " + pc +"%");
+ });
+
+ // 0-100, new volume setting
+ MK.volumeChanged.connect(function(v){
+ MK.setWindowTitle('volume set to ' + v);
+ });
+
+ Playdar.client.go();
+});
+</script>
+
+</head>
<body>
-<h1>test</h1>
-<a href="index.html">INDEX</a>
-<h3>Loading page</h3>
-<div id="trks">
+<!-- player controls, NP status etc -->
+<div id="topbar">
+ <table style="width:100%;">
+ <tr>
+ <td style="width:190px; margin-left:15px;">
+ <button id="playpausebtn" onclick="MK.togglePause();">pausetog</button>
+ <button id="stopbtn" onclick="MK.stop();">stop</button>
+ <select type="combo" id="vol" style="clear:left;" onchange="MK.setVolume(this.value);">
+ <option value="0">0</option>
+ <option value="25">25</option>
+ <option value="50">50</option>
+ <option value="75">75</option>
+ <option selected="selected" value="100">100</option>
+ </select>
+ </td>
+ <td style="padding:5px;">
+ <div style="border:1px solid green; height:60px;; width:100%; background-color:#CCCC99;
+ text-align:center; overflow:hidden; font-size:12px; font-face:sans-serif;">
+ <span id="np_track">The track title goes here</span><br/>
+ <span id="np_artist">Artist Name Here</span>
+ <table style="width:100%; height:15px; margin:0; padding:0; font-face: fixed; font-size:14px;">
+ <tr>
+ <td style="text-align:right; width:60px;" id="np_elapsed">00:00</td>
+ <td style="padding-left: 10px; padding-right:10px;">
+ <div style="height:3px; width:100%; border:1px solid grey; clear:left;" id="scrubber">
+ </div>
+ </td>
+ <td style="text-align:left; width:60px;" id="np_remaining">-00:00</td>
+ </table>
+ </div>
+ </td>
+ <td style="width: 200px; text-align:center; ">
+ SEARCH(todo)
+ </td>
+ </tr>
+ </table>
+</div>
+
+<div id="left-sidebar"> left-sidebar </div>
+<div id="content">
+<h3 id="h">Loading playlist</h3>
+
+<table id="tbl" style="width:100%; height:100%;">
+ <thead>
+ <tr style="font-weight:bold; text-align:left;">
+ <th>Artist</th> <th>Track</th> <th>Status</th>
+ </tr>
+ </thead>
+ <tbody style="" id="playlist">
+ </tbody>
+</table>
+
<script type="text/javascript">
-var req = new XMLHttpRequest();
-req.open("GET", "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", false);
-req.send("");
-//alert("gottit");
-var doc = req.responseXML.documentElement;
-var tracks = doc.getElementsByTagName("trackList")[0].getElementsByTagName('track');
-//alert(tracks.length);
-var trklist=new Array();
-for(i=0; i<tracks.length; i++)
+
+function loadPlaylist()
{
- trk = tracks[i];
- var title = trk.getElementsByTagName('title')[0].firstChild.nodeValue;
- var artist = trk.getElementsByTagName('creator')[0].firstChild.nodeValue;
- trklist[i]={'artist': artist, 'track': title};
- document.write("<div id=\"t"+i+"\">" + artist + " - " + title + " </div><br/>");
+ var req = new XMLHttpRequest();
+ req.open("GET", "http://ws.audioscrobbler.com/1.0/tag/metal/toptracks.xspf", false);
+ //req.open("GET", "toptracks.xspf", false);
+ req.send("");
+ var doc = req.responseXML.documentElement;
+ var tracks = doc.getElementsByTagName("trackList")[0].getElementsByTagName('track');
+ $('#h').innerHTML = tracks.length + ' tracks loaded';
+ for(i=0; i<tracks.length; i++)
+ {
+ trk = tracks[i];
+ var title = trk.getElementsByTagName('title')[0].firstChild.nodeValue;
+ var artist = trk.getElementsByTagName('creator')[0].firstChild.nodeValue;
+ var qid = Playdar.Util.generate_uuid();
+
+ var tr = document.createElement('tr');
+ tr.className = (i%2==0)?'even':'odd';
+ tr.id=qid;
+ var tdart = document.createElement('td');
+ tdart.appendChild(document.createTextNode(artist));
+ var tdtrk = document.createElement('td');
+ tdtrk.appendChild(document.createTextNode(title));
+ var tdstatus = document.createElement('td');
+ tdstatus.appendChild(document.createTextNode('resolving...'));
+ tdstatus.id=qid+'_status';
+ tr.appendChild(tdart);
+ tr.appendChild(tdtrk);
+ tr.appendChild(tdstatus);
+ document.getElementById('playlist').appendChild(tr);
+ Playdar.client.resolve(artist, title, "", qid);
+ }
}
</script>
-</div>
-<div id="res"></div>
+
<script type="text/javascript">
Playdar.USE_JSONP=false;
+ Playdar.USE_STATUS_BAR=false;
Playdar.setupClient({
// Called when the browser is authorised to query Playdar.
onAuth: function () {
- // At this point, we can query the Playdar API for a track and start polling for matches.
- for(j=0;j<trklist.length;j++)
- {
- Playdar.client.resolve(trklist[j].artist, trklist[j].track, "", 't'+j);
- }
+ loadPlaylist();
},
// Called in response to each poll with the results so far.
onResults: function (response, lastPoll) {
// console.log('Polling ' + response.qid);
if (lastPoll && response) {
- var d = document.getElementById(response.qid);
+ var d = $('#'+response.qid);
if(response.results.length == 0)
{
- d.style.textDecoration='line-through';
+ d.css({'textDecoration':'line-through'});
+ $('#'+response.qid+'_status').innerHTML = "not found";
}else{
+ $('#'+response.qid+'_status').innerHTML = response.results.length +
+ " results, " + +response.results[0].score;
var url="http://localhost:60210/sid/"+response.results[0].sid;
- d.innerHTML = '<a href="#" onclick="MK.play(\''+url+'\'); return false;">' + d.innerHTML + '</a>' + "<br/>" + url;
+ d.onclick = function(){
+ $('#np_artist').innerHTML = response.results[0].artist;
+ $('#np_track').innerHTML = response.results[0].track;
+ MK.play(url);
+ };
+// d.innerHTML = '<a href="#" onclick="MK.play(\''+url+'\'); return false;">' + d.innerHTML + '</a>' + "<br/>" + url;
}
-//document.getElementById("res").innerHTML=JSON.stringify(response);
- // Take a look at the final response.
- //console.dir(response);
}
}
});
- Playdar.client.go();
</script>
-
+fin
+</div>
</body></html>

0 comments on commit e294af4

Please sign in to comment.
Something went wrong with that request. Please try again.