-
Notifications
You must be signed in to change notification settings - Fork 9
/
omx_control.php
executable file
·126 lines (102 loc) · 2.12 KB
/
omx_control.php
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
<?php
error_reporting(E_ALL);
require_once 'cfg.php';
require_once 'JsHttpRequest.php';
$JsHttpRequest = new JsHttpRequest ( 'windows-1251' );
function play($file) {
$err = '';
exec('pgrep omxplayer', $pids); //omxplayer
if ( empty($pids) ) {
@unlink (FIFO);
posix_mkfifo(FIFO, 0777);
chmod(FIFO, 0777);
shell_exec ( getcwd().'/omx_php.sh '.escapeshellarg($file));
$out = 'playing '.basename($file);
} else {
$err = 'omxplayer is already runnning';
}
return array ( 'res' => $out, 'err' => $err );
}
function send($command) {
$err = '';
exec('pgrep omxplayer', $pids);
if ( !empty($pids) ) {
if ( is_writable(FIFO) ) {
if ( $fifo = fopen(FIFO, 'w') ) {
stream_set_blocking($fifo, false);
fwrite($fifo, $command);
fclose($fifo);
if ($command == 'q') {
sleep (1);
@unlink(FIFO);
$out = 'stopped';
}
}
}
} else {
$err .= 'not running';
}
return array ( 'res' => $out, 'err' => $err );
}
$act = $_REQUEST['act'];
unset($result);
switch ($act) {
case 'play':
$result = play($_REQUEST['arg']);
break;
case 'stop';
$result = send('q');
break;
case 'pause';
$result = send('p');
break;
case 'volup';
$result = send('+');
break;
case 'voldown';
$result = send('-');
break;
case 'seek-30';
$result = send(pack('n',0x5b44));
break;
case 'seek30';
$result = send(pack('n',0x5b43));
break;
case 'seek-600';
$result = send(pack('n',0x5b42));
break;
case 'seek600';
$result = send(pack('n',0x5b41));
break;
case 'speedup';
$result = send('1');
break;
case 'speeddown';
$result = send('2');
break;
case 'nextchapter';
$result = send('o');
break;
case 'prevchapter';
$result = send('i');
break;
case 'nextaudio';
$result = send('k');
break;
case 'prevaudio';
$result = send('j');
break;
case 'togglesubtitles';
$result = send('s');
break;
case 'nextsubtitles';
$result = send('m');
break;
case 'prevsubtitles';
$result = send('n');
break;
default:
$err = 'wrong command';
}
$GLOBALS['_RESULT'] = $result;
?>