-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo_control.py
executable file
·62 lines (53 loc) · 2.01 KB
/
video_control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import RPi.GPIO as GPIO
import time
# Path to the FIFO file that mplayer is monitoring
FIFO_PATH = "/home/pi/video_fifo" # Adjust to your actual FIFO file path
# Define GPIO pins for the buttons (replace with actual pin numbers)
BUTTON_PINS = {
'pause': 17, # Pause button GPIO pin
'fast_forward': 22, # Fast forward 10 seconds GPIO pin
'rewind': 23, # Rewind 10 seconds GPIO pin
'quit': 27 # Quit mplayer GPIO pin
}
def send_command_to_mplayer(command):
"""Send the command to the mplayer instance via the FIFO."""
if os.path.exists(FIFO_PATH):
with open(FIFO_PATH, 'w') as fifo:
fifo.write(command + '\n')
else:
print(f"FIFO file {FIFO_PATH} not found.")
def button_callback(channel):
"""Handle button presses and control mplayer actions."""
if channel == BUTTON_PINS['pause']:
print("Pause button pressed")
send_command_to_mplayer("pause")
elif channel == BUTTON_PINS['fast_forward']:
print("Fast forward button pressed")
send_command_to_mplayer("seek 10")
elif channel == BUTTON_PINS['rewind']:
print("Rewind button pressed")
send_command_to_mplayer("seek -10")
elif channel == BUTTON_PINS['quit']:
print("Quit button pressed")
send_command_to_mplayer("quit")
GPIO.cleanup()
exit()
def main():
# Set GPIO numbering to Broadcom (BCM)
GPIO.setmode(GPIO.BCM)
# Set up each button pin as input with pull-up resistors and attach callback
for pin in BUTTON_PINS.values():
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(pin, GPIO.FALLING, callback=button_callback, bouncetime=300)
#print("Monitoring buttons for mplayer control.")
try:
# Keep the script running to monitor button presses
while True:
time.sleep(0.1)
except KeyboardInterrupt:
print("Exiting...")
finally:
GPIO.cleanup()
if __name__ == "__main__":
main()