forked from rikkertkoppes/omxcontrol
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (44 loc) · 1.05 KB
/
index.js
File metadata and controls
52 lines (44 loc) · 1.05 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
var exec = require('child_process').exec;
var parseurl = require('url');
var pipe = false;
var map = false;
var DEFAULT_PATH = '/omx';
function omx(mapper) {
map = mapper;
}
omx.start = function(fn) {
if (!pipe) {
pipe = 'omxcontrol';
exec('mkfifo '+pipe);
}
cb(fn);
function cb(fn) {
console.log(fn);
exec('omxplayer -o hdmi "'+fn+'" < '+pipe,function(error, stdout, stderr) {
console.log(stdout);
});
exec('echo . > '+pipe);
}
};
omx.sendKey = function(key) {
if (!pipe) return;
exec('echo -n '+key+' > '+pipe);
};
omx.mapKey = function(command,key,then) {
omx[command] = function() {
omx.sendKey(key);
if (then) {
then();
}
};
};
omx.mapKey('pause','p');
omx.mapKey('quit','q',function() {
exec('rm '+pipe);
pipe = false;
});
omx.mapKey('play','.');
omx.mapKey('forward',"\x5b\x43");
omx.mapKey('backward',"\x5b\x44");
omx.mapKey('subs', 'm');
module.exports = omx;