- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
Latest commit
141 lines (106 loc) · 2.98 KB
/
Copy pathscript.js
File metadata and controls
141 lines (106 loc) · 2.98 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
varsp=getSpotifyApi(1);
varm=sp.require("sp://import/scripts/api/models");
varv=sp.require("sp://import/scripts/api/views");
varui=sp.require('sp://import/scripts/dnd');
varsocket;
//exports.init = init;
functioninit(){
updatePageWithTrackDetails();
sp.trackPlayer.addEventListener("playerStateChanged",function(event){
// Only update the page if the track changed
if(event.data.curtrack==true){
updatePageWithTrackDetails();
}
});
}
functionupdatePageWithTrackDetails(){
varheader=document.getElementById("header");
// This will be null if nothing is playing.
varplayerTrackInfo=sp.trackPlayer.getNowPlayingTrack();
if(playerTrackInfo==null){
header.innerText="Nothing playing right now:)!";
}else{
vartrack=playerTrackInfo.track;
header.innerText=track.name+" on the album "+track.album.name+" by "+track.album.artist.name+".";
}
}
functionsearchGoogleForSpotify(){
varreq=newXMLHttpRequest();
req.open("GET","https://www.googleapis.com/customsearch/v1?q=spotify",true);
req.onreadystatechange=function(){
console.log(req.status);
if(req.readyState==4){
if(req.status==200){
console.log("Search complete");
}
}
};
req.send();
}
functiondoConnect(){
socket=io.connect('http://localhost:8000');
socket.on("connect",onConnect)
}
functiononConnect(evt){
console.log(evt);
return;
/*
data = new Object();
data.action = "join";
data.room = $("#room").val();
websocket.send(JSON.stringify(data));
*/
}
functiononClose(evt){
console.log(evt);
}
functiononMessage(evt){
console.log(evt);
try{
data=JSON.parse(evt.data);
console.log(data);
if(data.message){
$("#status").text("Status: "+data.message);
}
if(data.action=="play"){
m.Track.fromURI(data.uri,tplPlayer.play);
}
}catch(e){
console.log(e);
}
}
functiononError(evt){
console.log(evt);
}
// Custom fields, playlist with tracks of varying availability.
vartpl=newm.Playlist();
vartplPlayer=newv.Player();
vartempList=newv.List(tpl);
tpl.add(m.Track.fromURI("spotify:track:4z4t4zEn4ElVPGmDWCzRQf"));
tpl.add(m.Track.fromURI("http://open.spotify.com/track/7E8JGVhbwWgAQ1DtfatQEl"));
tpl.add(m.Track.fromURI("spotify:track:40YBc3mR3yyqyYvtesQOMj"));
tpl.add(m.Track.fromURI("spotify:local:Rolling+Stones:A+Bigger+Bang:Rain+Fall+Down:293"));
tplPlayer.track=tpl.get(0);
tplPlayer.context=tpl;
$(document).ready(function(){
init();
$("h2").text("Niggah plz!");
varlib=sp.core.library.getPlaylists();
console.log(sp,sp.core,sp.core.library,sp.desktop);
document.body.appendChild(tplPlayer.node);
document.body.appendChild(tempList.node);
$(".connect").click(function(){
doConnect();
});
$(".playBtn").click(function(){
data=newObject();
data.action="play";
data.room=$("#room").val();
websocket.send(JSON.stringify(data));
});
/*
for(i in lib){
$("#playlists").append("<li>"+lib[i].name+"</li>");
}
*/
});