Created
August 25, 2024 13:24
-
-
Save kubo6472/5eb2593a05c22d1b89ff30e94a245c89 to your computer and use it in GitHub Desktop.
player for sorrywecan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
from omxplayer import OMXPlayer | |
from time import sleep | |
from pathlib import Path | |
# GPIO pin number : | |
light = 7 | |
# Setup the player as shown in omxplayer-wrapper examples : | |
path = Path('./video.mp4') | |
# the on and off times in seconds | |
on_target = 1 | |
off_target = 3 | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(light, GPIO.OUT) | |
player = OMXPlayer(path, args=['--no-osd', '--blank']) | |
player.pause() | |
sleep(5) | |
player.play() | |
# Make a query to position() inside infinite loop | |
while (1): | |
try: | |
position = int(player.position()) | |
except: | |
# You will get an OMXPlayerDeadError eventually | |
break | |
if position >= on_target and position <= off_target: | |
GPIO.output(light, GPIO.HIGH) | |
print("This is where the first GPIO should be triggered") | |
# Check position again in one second. | |
# sleep works, but you might want to find an alternative | |
sleep(1) | |
player.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment