-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotify.js
More file actions
88 lines (72 loc) · 1.94 KB
/
Copy pathspotify.js
File metadata and controls
88 lines (72 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var spotify = {}
curTime = function() {
var date = new Date();
return date.getTime();
}
update_track = function() {
spotify.models.player.load("track", "position", "playing").done(function(p) {
spotify._position = p.position;
spotify._track = p.track;
spotify._playing = p.playing;
spotify._fetch_time = curTime();
});
}
spotify.position = function() {
if (!spotify._playing) {
return spotify._position;
}
var now = curTime();
//if (now - spotify._fetch_time > 5000)
// update_track();
return spotify._position + (now - spotify._fetch_time);
}
spotify.track = function(callback) {
spotify.models.player.load("track").done(function(d) {
spotify._length = d.duration;
spotify._track = d.track;
callback(d);
});
}
spotify.track_change = function(callback) {
spotify.models.player.addEventListener("change:track", function() {
spotify.track(callback);
});
}
spotify.playing = function(callback) {
spotify.models.player.load("playing").done(function(d) {
callback(d);
});
}
spotify.playing_change = function(callback) {
spotify.models.player.addEventListener("change:playing", function() {
spotify.playing(callback);
});
}
spotify.pause = function() {
spotify.models.player.pause();
}
spotify.play = function() {
spotify.models.player.play();
}
require(['$api/models'], function(models) {
spotify.models = models;
update_track()
main.init();
echonest.init();
//spotify.playing_change(function(b) {console.log("playing: ", b)});
spotify.track_change(function() {
// update the position now that we've changed track.
spotify._fetch_time = 0;
spotify.position();
});
spotify.playing_change(function (arg) {
spotify._position = arg.position;
spotify._playing = arg.playing;
spotify._fetch_time = curTime();
});
spotify.models.player.addEventListener("change:position", function (arg) {
spotify._position = arg.target.position;
spotify._playing = arg.target.playing;
spotify._fetch_time = curTime();
})
});