This commit is contained in:
jimmy 2022-07-20 21:14:04 +12:00
parent 63defcc7c7
commit f9da3a45f0
3 changed files with 22 additions and 5 deletions

View File

@ -1,33 +1,49 @@
# importing vlc module # importing vlc module
from os import listdir
from os.path import isfile, join
from random import randint
from time import sleep from time import sleep
import paho.mqtt.client as mqtt import paho.mqtt.client as mqtt
from video import Video from video import Video
import multiprocessing import multiprocessing
import sys import sys
from random import randint
class App: class App:
def __init__(self, client, x, y): def __init__(self, client, x, y):
self.client = client self.client = client
self.video = Video(x, y) self.video = Video(x, y)
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
print(self.videos)
print(self.videos[randint(0, len(self.videos))])
def on_connect(self, client, userdata, flags, rc): def on_connect(self, client, userdata, flags, rc):
print("Connected with result code "+str(rc)) print("Connected with result code "+str(rc))
self.client.subscribe("video") self.client.subscribe("slave")
def on_message(self, client, userdata, msg): def on_message(self, client, userdata, msg):
print(msg.topic+" "+str(msg.payload)) print(msg.topic+" "+str(msg.payload))
if msg.payload == b'start': if msg.payload == b'idle':
print("Start") print("Idle")
self.x = multiprocessing.Process(target = self.video.start, args=("slave/sample-mp4-file.mp4",)) self.x = multiprocessing.Process(target = self.idle)
self.x.start() self.x.start()
elif msg.payload == b'stop': elif msg.payload == b'stop':
print("Stop") print("Stop")
self.x.terminate() self.x.terminate()
def idle(self):
while True:
#if self.x is not None:
# self.x.terminate()
video = self.videos[randint(0, len(self.videos))]
self.video.start(video)
def main(): def main():
client = mqtt.Client() client = mqtt.Client()
@ -35,7 +51,7 @@ def main():
client.on_connect = app.on_connect client.on_connect = app.on_connect
client.on_message = app.on_message client.on_message = app.on_message
client.connect("10.173.54.35", 1883, 60) client.connect("10.1.1.162", 1883, 60)
client.loop_forever() client.loop_forever()

Binary file not shown.

View File

@ -50,6 +50,7 @@ class Video:
# Closes all the frames # Closes all the frames
cv2.destroyAllWindows() cv2.destroyAllWindows()
if __name__ == "__main__": if __name__ == "__main__":
video = Video(0, 0) video = Video(0, 0)
x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",)) x = multiprocessing.Process(target = video.start, args=("slave/sample-mp4-file.mp4",))