-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathn4m-vlc.js
177 lines (156 loc) · 2.88 KB
/
n4m-vlc.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
//https://github.com/alexandrucancescu/node-vlc-client
const max = require('max-api');
const VLC = require('vlc-client');
max.post("hello n4m-vlc");
let vlc = null;
let connected = false;
function isconnected() {
if(!connected) {
max.post("not connected to VLC");
}
return connected;
}
max.addHandlers({
connect: () => {
vlc = new VLC.Client({
ip: "localhost", // for some reason passing localhost here stopped working on my machine
//ip: "192.168.1.4",// and I was forced to use the actual IP to get it working again ¯\_(ツ)_/¯
port: 8080,
password: "vlc" // set your password here
});
if(vlc) {
vlc.status().then((status) => {
connected = true;
max.post("connected to VLC");
max.post(status);
})
.catch(err => {
max.post('connection error');
max.post(err);
});
}
else {
max.post("error connecting to VLC");
}
},
get_status: (dname) => {
if(isconnected()) {
vlc.status().then((status) => {
max.setDict(dname, status);
})
}
},
get_playlist: () => {
if(isconnected()) {
vlc.getPlaylist().then((plist) => {
if(plist.length) {
max.post(`got playlist with ${plist.length} items`)
max.outlet('playlist');
plist.forEach(plitem => {
max.outlet("item", plitem.name);
max.outlet("id", plitem.id);
//max.post(plitem);
});
}
else {
max.post(`got empty playlist`)
max.outlet('playlist');
}
})
.catch(err => {
max.post('get_playlist error');
max.post(err);
});
}
},
fullscreen: () => {
if(isconnected()) {
vlc.toggleFullscreen()
}
},
clear: () => {
if(isconnected()) {
vlc.emptyPlaylist().then(() => {
max.outlet('playlist');
});
}
},
vol : (val) => {
if(isconnected()) {
vlc.setVolume(val * 100.);
}
},
loopall : (val) => {
if(isconnected()) {
vlc.setLooping(val > 0);
}
},
loop : (val) => {
if(isconnected()) {
vlc.setRepeating(val > 0);
}
},
add_file: (uri) => {
if(isconnected()) {
uri = "file://" + uri;
vlc.addToPlaylist(uri).then(() => {
max.outlet("playlistnotify")
})
.catch(err => {
max.post('error loading File');
max.post(err);
})
}
},
add_url: (url) => {
if(isconnected()) {
vlc.addToPlaylist(url).then(() => {
max.outlet("playlistnotify")
})
.catch(err => {
max.post('error loading URL');
max.post(err);
})
}
},
play_item: (id) => {
if(isconnected()) {
vlc.playFromPlaylist(id);
}
},
set_play: (state) => {
if(isconnected()) {
try {
if(state === "start") {
if(vlc.isStopped()) {
vlc.next();
}
else {
vlc.play()
}
}
else if(state === "stop") {
vlc.stop()
}
else if(state === "pause") {
vlc.togglePlay()
}
else if(state === "next") {
vlc.next()
}
else if(state === "previous") {
vlc.previous()
}
}
catch(err) {
max.post('set_play error');
max.post(err);
}
}
},
set_position: (pos) => {
if(isconnected()) {
vlc.setProgress(pos * 100);
}
}
});