Hello,
I am using the following code to play a video using a button press. It is set up so that the video starts playing when the button is pressed, and is stops playing when the button is released.
Currently everything is working as expected.
Right now, the video will play till the end and then stop, assuming you keep the button pressed.
What I am looking for is a way to loop the video back to the beginning if you keep the button pressed instead of stopping when the video is finished.
Regards,
Robert
App Versions:
os - Linux 10 Buster
script - Python3
player - OMXPlayer 08/01/2019
wrapper - omxplayer-wrapper 0.3.2
playvid.py file code:
I am using the following code to play a video using a button press. It is set up so that the video starts playing when the button is pressed, and is stops playing when the button is released.
Currently everything is working as expected.
Right now, the video will play till the end and then stop, assuming you keep the button pressed.
What I am looking for is a way to loop the video back to the beginning if you keep the button pressed instead of stopping when the video is finished.
Regards,
Robert
App Versions:
os - Linux 10 Buster
script - Python3
player - OMXPlayer 08/01/2019
wrapper - omxplayer-wrapper 0.3.2
playvid.py file code:
#!/usr/bin/env python3 from omxplayer.player import OMXPlayer from time import sleep from signal import pause from gpiozero import Button buttonState = False player = None def playerExit(exit_code): global buttonState buttonState = False def videoStart(): global buttonState global player buttonState = True player = OMXPlayer(videoFile) player.set_volume(1) player.exitEvent += lambda _, exit_code: playerExit(exit_code) def videoStop(): global buttonState global player if player != None: if buttonState: player.stop() try: videoFile = "/home/pi/Videos/chase.mp4" buttonPlay = Button(21) buttonPlay.when_pressed = videoStart buttonPlay.when_released = videoStop pause() finally: pass