Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.

Commit 35a5819

Browse files
committed
process, server: omxplayer-wrapper bringup
1 parent 96e2484 commit 35a5819

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

process.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,29 @@
33
import threading
44
import logging
55
import json
6+
import time
7+
8+
from omxplayer.player import OMXPlayer
9+
610
logger = logging.getLogger("RaspberryCast")
711
volume = 0
12+
player = None
13+
14+
def playeraction(action):
15+
global player
16+
try:
17+
player.action(action)
18+
except:
19+
pass
820

921

1022
def launchvideo(url, config, sub=False):
1123
setState("2")
1224

13-
os.system("echo -n q > /tmp/cmd &") # Kill previous instance of OMX
25+
try:
26+
player.quit() #Kill previous instance of OMX
27+
except:
28+
pass
1429

1530
if config["new_log"]:
1631
os.system("sudo fbi -T 1 -a --noverbose images/processing.jpg")
@@ -25,8 +40,6 @@ def launchvideo(url, config, sub=False):
2540
new_log=config["new_log"]))
2641
thread.start()
2742

28-
os.system("echo . > /tmp/cmd &") # Start signal for OMXplayer
29-
3043

3144
def queuevideo(url, config, onlyqueue=False):
3245
logger.info('Extracting source video URL, before adding to queue...')
@@ -42,7 +55,6 @@ def queuevideo(url, config, onlyqueue=False):
4255
kwargs=dict(width=config["width"], height=config["height"],
4356
new_log=config["new_log"]))
4457
thread.start()
45-
os.system("echo . > /tmp/cmd &") # Start signal for OMXplayer
4658
else:
4759
if out is not None:
4860
with open('video.queue', 'a') as f:
@@ -140,6 +152,7 @@ def playlistToQueue(url, config):
140152

141153

142154
def playWithOMX(url, sub, width="", height="", new_log=False):
155+
global player
143156
logger.info("Starting OMXPlayer now.")
144157

145158
logger.info("Attempting to read resolution from configuration file.")
@@ -150,19 +163,19 @@ def playWithOMX(url, sub, width="", height="", new_log=False):
150163
resolution = " --win '0 0 {0} {1}'".format(width, height)
151164

152165
setState("1")
166+
args = "-b" + resolution + " --vol " + str(volume)
153167
if sub:
154-
os.system(
155-
"omxplayer -b -r -o both '" + url + "'" + resolution +
156-
" --vol " + str(volume) +
157-
" --subtitles subtitle.srt < /tmp/cmd"
158-
)
168+
player = OMXPlayer(url, args + " --subtitles subtitle.srt")
159169
elif url is None:
160170
pass
161171
else:
162-
os.system(
163-
"omxplayer -b -r -o both '" + url + "' " + resolution + " --vol " +
164-
str(volume) + " < /tmp/cmd"
165-
)
172+
player = OMXPlayer(url, args)
173+
174+
try:
175+
while not player.playback_status() == "Stopped": # Wait until video finished or stopped
176+
time.sleep(0.5)
177+
except:
178+
pass
166179

167180
if getState() != "2": # In case we are again in the launchvideo function
168181
setState("0")
@@ -181,7 +194,6 @@ def playWithOMX(url, sub, width="", height="", new_log=False):
181194
new_log=new_log),
182195
)
183196
thread.start()
184-
os.system("echo . > /tmp/cmd &") # Start signal for OMXplayer
185197
else:
186198
logger.info("Playlist empty, skipping.")
187199
if new_log:

server.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
from urllib import urlretrieve
1313
from bottle import Bottle, SimpleTemplate, request, response, \
1414
template, run, static_file
15+
1516
from process import launchvideo, queuevideo, playlist, \
16-
setState, getState, setVolume
17+
setState, getState, setVolume, playeraction
18+
19+
from omxplayer.keys import *
1720

1821
if len(sys.argv) > 1:
1922
config_file = sys.argv[1]
@@ -41,13 +44,6 @@
4144
ch.setFormatter(formatter)
4245
root.addHandler(ch)
4346

44-
try:
45-
os.mkfifo("/tmp/cmd")
46-
except OSError as e:
47-
# 17 means the file already exists.
48-
if e.errno != 17:
49-
raise
50-
5147
if config["new_log"]:
5248
os.system("sudo fbi -T 1 --noverbose -a images/ready.jpg")
5349

@@ -171,27 +167,27 @@ def video():
171167
control = request.query['control']
172168
if control == "pause":
173169
logger.info('Command : pause')
174-
os.system("echo -n p > /tmp/cmd &")
170+
playeraction(PAUSE)
175171
return "1"
176172
elif control in ["stop", "next"]:
177173
logger.info('Command : stop video')
178-
os.system("echo -n q > /tmp/cmd &")
174+
playeraction(EXIT)
179175
return "1"
180176
elif control == "right":
181177
logger.info('Command : forward')
182-
os.system("echo -n $'\x1b\x5b\x43' > /tmp/cmd &")
178+
playeraction(SEEK_FORWARD_SMALL)
183179
return "1"
184180
elif control == "left":
185181
logger.info('Command : backward')
186-
os.system("echo -n $'\x1b\x5b\x44' > /tmp/cmd &")
182+
playeraction(SEEK_BACK_SMALL)
187183
return "1"
188184
elif control == "longright":
189185
logger.info('Command : long forward')
190-
os.system("echo -n $'\x1b\x5b\x41' > /tmp/cmd &")
186+
playeraction(SEEK_FORWARD_LARGE)
191187
return "1"
192188
elif control == "longleft":
193189
logger.info('Command : long backward')
194-
os.system("echo -n $'\x1b\x5b\x42' > /tmp/cmd &")
190+
playeraction(SEEK_BACK_LARGE)
195191
return "1"
196192

197193

@@ -200,10 +196,10 @@ def sound():
200196
vol = request.query['vol']
201197
if vol == "more":
202198
logger.info('REMOTE: Command : Sound ++')
203-
os.system("echo -n + > /tmp/cmd &")
199+
playeraction(INCREASE_VOLUME)
204200
elif vol == "less":
205201
logger.info('REMOTE: Command : Sound --')
206-
os.system("echo -n - > /tmp/cmd &")
202+
playeraction(DECREASE_VOLUME)
207203
setVolume(vol)
208204
return "1"
209205

0 commit comments

Comments
 (0)