halloween.py - play on second screen

This commit is contained in:
2023-10-30 20:42:46 +01:00
parent 6d4afc211e
commit 262c4c1e39
+8 -8
View File
@@ -27,7 +27,9 @@ class Player(object):
_instance = None _instance = None
# we need a subprocess object for the first poll() so we just let the video run once # we need a subprocess object for the first poll() so we just let the video run once
vid_process = subprocess.Popen(["mplayer","/home/tilman/Videos/halloween-04-friendly_ghost_4.mp4"], stdout=subprocess.PIPE) vid_process = subprocess.Popen(["ls","-l"], stdout=subprocess.PIPE)
last_no1 = 0
last_no2 = 0
def __new__(cls): def __new__(cls):
if cls._instance is None: if cls._instance is None:
@@ -39,8 +41,6 @@ class Player(object):
class MyServer(BaseHTTPRequestHandler): class MyServer(BaseHTTPRequestHandler):
player = Player() player = Player()
last_no = 0
last_no2 = 0
def do_GET(self): def do_GET(self):
self.send_response(200) self.send_response(200)
@@ -52,21 +52,21 @@ class MyServer(BaseHTTPRequestHandler):
if (self.player.vid_process.poll() is not None): if (self.player.vid_process.poll() is not None):
rnd_no = random.randint(0,6) rnd_no = random.randint(0,6)
while (rnd_no == self.last_no or rnd_no == self.last_no2): while (rnd_no == self.player.last_no1 or rnd_no == self.player.last_no2):
rnd_no = random.randint(0,6) rnd_no = random.randint(0,6)
self.last_no2 = self.last_no self.player.last_no2 = self.player.last_no1
self.last_no = rnd_no self.player.last_no1 = rnd_no
link = videos[rnd_no] link = videos[rnd_no]
print('START ' + link + '\n') print('START ' + link + '\n')
self.wfile.write(bytes("START " + videos[rnd_no], "utf-8")) self.wfile.write(bytes("START " + videos[rnd_no], "utf-8"))
cmd = "mplayer -xineramascreen 2 -fs %s"%(link) cmd = "mplayer -xineramascreen 2 -fs %s"%(link)
self.player.vid_process = subprocess.Popen(["mplayer",link], stdout=subprocess.PIPE) self.player.vid_process = subprocess.Popen(["mplayer","-xineramascreen", "2", "-fs", link], stdout=subprocess.PIPE)
else: else:
print('RUNNING\n') print('RUNNING\n')
self.wfile.write(bytes("RUNNING " + videos[self.last_no], "utf-8")) self.wfile.write(bytes("RUNNING " + videos[self.player.last_no1], "utf-8"))
self.wfile.write(bytes("</p>", "utf-8")) self.wfile.write(bytes("</p>", "utf-8"))
self.wfile.write(bytes("</body></html>", "utf-8")) self.wfile.write(bytes("</body></html>", "utf-8"))