-
Notifications
You must be signed in to change notification settings - Fork 0
/
omxplayer.js
178 lines (142 loc) · 2.43 KB
/
omxplayer.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
178
const childProcess = require('child_process');
let OMXPLAYER_PROCESS;
let playing = false;
let paused = false;
function writeCommand(command) {
if (OMXPLAYER_PROCESS) {
OMXPLAYER_PROCESS.stdin.write(command);
}
}
function init(source) {
if (OMXPLAYER_PROCESS) {
quit();
if (!OMXPLAYER_PROCESS.killed) {
OMXPLAYER_PROCESS.kill();
}
}
const _arguments = ['-o', 'hdmi', source];
OMXPLAYER_PROCESS = childProcess.spawn('omxplayer', _arguments);
playing = true;
OMXPLAYER_PROCESS.on('close', () => {
OMXPLAYER_PROCESS = null;
playing = false;
paused = false;
});
return OMXPLAYER_PROCESS;
}
function isPlaying() {
return playing;
}
function play() {
if (paused) {
togglePlay();
}
}
function pause() {
if (!paused) {
togglePlay();
}
}
function decreaseSpeed() {
writeCommand(1);
}
function increaseSpeed() {
writeCommand(2);
}
function rewind() {
writeCommand('<');
}
function fastForward() {
writeCommand('>');
}
function showInfo() {
writeCommand('z');
}
function previousAudioStream() {
writeCommand('j');
}
function nextAudioStream() {
writeCommand('k');
}
function previousChapter() {
writeCommand('i');
}
function nextChapter() {
writeCommand('o');
}
function previousSubtitleStream() {
writeCommand('n');
}
function nextSubtitleStream() {
writeCommand('m');
}
function toggleSubtitles() {
writeCommand('s');
}
function showSubtitles() {
writeCommand('w');
}
function hideSubtitles() {
writeCommand('x');
}
function decreaseSubtitleDelay() {
writeCommand('d');
}
function increaseSubtitleDelay() {
writeCommand('f');
}
function quit() {
writeCommand('q');
}
function togglePlay() {
paused = !paused;
writeCommand('p');
}
function decreaseVolume() {
writeCommand('-');
}
function increaseVolume() {
writeCommand('+');
}
function seekBack30() {
writeCommand('\u001b[D');
}
function seekForward30() {
writeCommand('\u001b[C');
}
function seekBack600() {
writeCommand('\u001b[B');
}
function seekForward600() {
writeCommand('\u001b[A');
}
module.exports = {
isPlaying,
init,
play,
pause,
decreaseSpeed,
increaseSpeed,
rewind,
fastForward,
showInfo,
previousAudioStream,
nextAudioStream,
previousChapter,
nextChapter,
previousSubtitleStream,
nextSubtitleStream,
toggleSubtitles,
showSubtitles,
hideSubtitles,
decreaseSubtitleDelay,
increaseSubtitleDelay,
quit,
togglePlay,
decreaseVolume,
increaseVolume,
seekBack30,
seekForward30,
seekBack600,
seekForward600,
};