Работают следующие варианты использования
1. Если одна из кнопок отпущена, соответствующее видео воспроизводится с помощью omxplayer. Здесь видео и светодиод предварительно назначены каждой «кнопке».
Следующие варианты использования не работают
1. Если две кнопки отпущены, omxplayer
должно воспроизводить два видео на разделенном экране, а также должна работать светодиодная функция. Но в моем случае работает только светодиодная функциональность, а не видео.
2. То же самое происходит, когда отпускаются четыре кнопки, тогда omxplayer
не воспроизводит четыре видео в стиле квадранта, как CCTV, а также светодиодные функции.
#!/usr/bin/env python3
"""
CATALOG_V1.1
"""
import os
import time
import subprocess
from gpiozero import Button, LED
PRODUCTLEDPIN_1 = "BOARD35"
PRODUCTLEDPIN_2 = "BOARD38"
PRODUCTLEDPIN_3 = "BOARD31"
PRODUCTLEDPIN_4 = "BOARD32"
PRODUCTBUTTONPIN_1 = "BOARD37"
PRODUCTBUTTONPIN_2 = "BOARD40"
PRODUCTBUTTONPIN_3 = "BOARD33"
PRODUCTBUTTONPIN_4 = "BOARD36"
PRODUCTBUTTON_1 = Button(PRODUCTBUTTONPIN_1, bounce_time=0.01)
PRODUCTBUTTON_2 = Button(PRODUCTBUTTONPIN_2, bounce_time=0.01)
PRODUCTBUTTON_3 = Button(PRODUCTBUTTONPIN_3, bounce_time=0.01)
PRODUCTBUTTON_4 = Button(PRODUCTBUTTONPIN_4, bounce_time=0.01)
PRODUCTLED_1 = LED(PRODUCTLEDPIN_1, initial_value=1)
PRODUCTLED_2 = LED(PRODUCTLEDPIN_2, initial_value=1)
PRODUCTLED_3 = LED(PRODUCTLEDPIN_3, initial_value=1)
PRODUCTLED_4 = LED(PRODUCTLEDPIN_4, initial_value=1)
# False mean 0 or LOW
# True mean 1 or HIGH
def default_video():
""""This function first kill omxplayer and player default video """
os.system('killall omxplayer.bin')
os.system("omxplayer -o hdmi -b --win '0 0 1366 768' --loop /home/pi/Videos/default.mp4 &")
def default_1():
""""This function first kill omxplayer and player default video """
PRODUCTLED_1.off()
print("Release")
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
os.system("omxplayer -o hdmi -b --loop /home/pi/Videos/products1.mp4 &")
def default_2():
""""This function first kill omxplayer and player default video """
PRODUCTLED_2.off()
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
os.system("omxplayer -o hdmi -b --win '0 0 1366 768' --loop /home/pi/Videos/products2.mp4 &")
def default_3():
""""This function first kill omxplayer and player default video """
PRODUCTLED_3.off()
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
os.system("omxplayer -o hdmi -b --loop /home/pi/Videos/products3.mp4 &")
# default_video()
def default_4():
""""This function first kill omxplayer and player default video """
PRODUCTLED_4.off()
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
os.system("omxplayer -o hdmi -b --loop /home/pi/Videos/products4.mp4 &")
# default_video()
def product_1():
""""This function first kill omxplayer and player default video """
PRODUCTLED_1.on()
print("pressed")
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
default_video()
def product_2():
""""This function first kill omxplayer and player default video """
PRODUCTLED_2.on()
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
default_video()
def product_3():
""""This function first kill omxplayer and player default video """
PRODUCTLED_3.on()
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
default_video()
def product_4():
""""This function first kill omxplayer and player default video """
PRODUCTLED_4.on()
subprocess.Popen('killall omxplayer.bin',
stdout=subprocess.PIPE,
shell=True)
default_video()
def mainloop():
"""This function is the main loop"""
try:
while True: # Run forever
PRODUCTBUTTON_1.when_pressed = product_1
PRODUCTBUTTON_1.when_released = default_1
PRODUCTBUTTON_2.when_pressed = product_2
PRODUCTBUTTON_2.when_released = default_2
PRODUCTBUTTON_3.when_pressed = product_3
PRODUCTBUTTON_3.when_released = default_3
PRODUCTBUTTON_4.when_pressed = product_4
PRODUCTBUTTON_4.when_released = default_4
# 0000
if (PRODUCTBUTTON_1.value == 0
and PRODUCTBUTTON_2.value == 0
and PRODUCTBUTTON_3.value == 0
and PRODUCTBUTTON_4.value == 0):
print("0000")
os.system('killall omxplayer.bin')
os.system('omxplayer --win "0 0 683 384" --loop /home/pi/Videos/products1.mp4 | omxplayer --win "684 384 1366 768" --loop /home/pi/Videos/products2.mp4 | omxplayer --win "684 0 1366 384" --loop /home/pi/Videos/products4.mp4 | omxplayer --win "0 384 684 768" --loop /home/pi/Videos/products3.mp4')
# time.sleep(30)
# 1111
if (PRODUCTBUTTON_1.value == 1
and PRODUCTBUTTON_2.value == 1
and PRODUCTBUTTON_3.value == 1
and PRODUCTBUTTON_4.value == 1):
os.system('killall omxplayer.bin')
time.sleep(3)
os.system("omxplayer -o hdmi -b --loop /home/pi/Videos/default.mp4 &")
print("1111")
# 0011
if (PRODUCTBUTTON_1.value == 0
and PRODUCTBUTTON_2.value == 0
and PRODUCTBUTTON_3.value == 1
and PRODUCTBUTTON_4.value == 1):
print("0011")
os.system('killall omxplayer.bin')
time.sleep(3)
os.system(
'omxplayer --win "0 0 683 768" --loop /home/pi/Videos/products1.mp4 | omxplayer --win "684 0 1366 684" --loop /home/pi/Videos/products2.mp4')
finally:
PRODUCTLED_1.close()
PRODUCTLED_2.close()
PRODUCTLED_3.close()
PRODUCTLED_4.close()
if __name__ == "__main__":
mainloop()