Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix time
  • Loading branch information
waxzce committed Jul 22, 2012
1 parent 43bd999 commit c2249f3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app.js
Expand Up @@ -4,6 +4,7 @@ app = app = express(),
server = http.createServer(app),
io = require('socket.io').listen(server),
util = require('util'),
microtime = require('microtime'),
dospotify = require('./dospotify.js').instance.init(io),
musicqueue = require('./musicqueue.js').instance.init(dospotify);

Expand Down Expand Up @@ -54,6 +55,7 @@ function(req, res) {
app.get('/api/playing',
function(req, res) {
res.contentType('application/json');
cu_play['progress'] = microtime.now() - dospotify.current_track_start_time;
res.send(JSON.stringify(cu_play));
});

Expand Down
10 changes: 8 additions & 2 deletions dospotify.js
@@ -1,5 +1,5 @@
// version spotify app
var EventEmitter = require('events').EventEmitter;
var EventEmitter = require('events').EventEmitter, microtime = require('microtime');


var Dospotify = function() {
Expand All @@ -9,6 +9,9 @@ var Dospotify = function() {
this.country = 'US';
this.pass = 'tryo';
this.current_track = {};
this.current_track_start_time = 0;
this.current_track_timer = 0;
this.timeoutId = null;
return this;
}

Expand All @@ -25,8 +28,11 @@ p.play = function(t) {
console.log(e);
}
this.current_track = t;
this.current_track_start_time = microtime.now();

var timer = (Math.round(t.length)+1) * 1000;
var timeoutId = setTimeout(this.playing_is_finish.bind(this, t), timer);
this.current_track_timer = timer;
this.timeoutId = setTimeout(this.playing_is_finish.bind(this, t), timer);
};

p.playing_is_finish = function(t){
Expand Down
5 changes: 3 additions & 2 deletions package.json
Expand Up @@ -4,13 +4,14 @@
"scripts": {
"start": "app.js"
},
"version": "0.8.1-3",
"version": "0.8.1-4",
"engines": {
"node": "0.6.x"
},
"dependencies": {
"xmldom": "0.1.x",
"express": "3.x",
"socket.io": "0.9.x"
"socket.io": "0.9.x",
"microtime": "0.3.x"
}
}
2 changes: 1 addition & 1 deletion public/js/adminscript.js
Expand Up @@ -90,7 +90,7 @@ var MASTERPASS = '', OpenSpice = (function() {
$('#playlist_next').append(OpenSpice.templates.trackInQueue({
name: added.name,
artists: _.pluck(added.artists, 'name').join(', '),
href: track.href
href: added.href
}));
}
$('.fnct_rm').click(OpenSpice.ask_rm_this).addClass('fnct_rm_done').removeClass('fnct_rm');
Expand Down
29 changes: 28 additions & 1 deletion public/js/script.js
Expand Up @@ -49,7 +49,10 @@ var OpenSpice = (function() {
p.fetchCurrentTrack = function() {
$.ajax({
url: "/api/playing",
}).done(this.displayCurrentTrack);
}).done(function(data){
OpenSpice.displayCurrentTrack(data);
OpenSpice.manageTrackProgressionFirst(data);
});
};

p.fetchCountry = function() {
Expand Down Expand Up @@ -286,6 +289,30 @@ var OpenSpice = (function() {
}
}

p.manageTrackProgressionFirst = function(e) {
if (!_.isEmpty(e)) {
var t = e.length*1000000;
var te = e.progress;
var pct = Math.floor((te/t)*100);
var tr = Math.floor((t-te)/1000);
// console.log([t,te,pct,tr]);
var elem = $('#playing_box .progress .bar');
elem.stop(true, true);
elem.css({
'width': pct+'%',
'-webkit-transition': 'none',
'-ms-transition': 'none',
'-moz-transition': 'none',
'-o-transition': 'none',
'transition': 'none'
});
elem.animate({
'width': '100%'
},
tr);
}
}


return new Op();
})();
Expand Down

0 comments on commit c2249f3

Please sign in to comment.