问题描述
你好,我是 Python 新手,尝试在按钮上播放多个视频。 (试图用树莓 3 b 进行安装的设计师)。我有一个用于事件检测和回调函数的“主循环”。那部分工作。在我的函数 playVid1() 中,我尝试用我的视频打开 omxplayer。第一次它工作得很好,预计它似乎没有正确关闭播放器并且不会在循环中返回。当我第二次点击按钮时,播放器再次打开,但不再播放我的视频。如果有人可以帮助我,我会很高兴。任何提示?感谢并致以最诚挚的问候
import RPi.GPIO as GPIO
import time
import os
import sys
from subprocess import Popen
#pins on raspy
button1 = 23
button2 = 21
button3 = 19
button4 = 15
button5 = 13
button6 = 11
button7 = 7
button8 = 29
button9 = 31
led1 = 36
led2 = 26
led3 = 24
led4 = 22
led5 = 18
led6 = 16
led7 = 12
led8 = 38
led9 = 40
movie1 = ("/home/pi/Videos/video1.mp4")
video1_length = 10.0 # seconds before led turns off and
player = False
def setup():
GPIO.setmode(GPIO.BOARD)
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led1,GPIO.OUT)
GPIO.setup(button2,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led2,GPIO.OUT)
GPIO.setup(button3,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led3,GPIO.OUT)
GPIO.setup(button4,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led4,GPIO.OUT)
GPIO.setup(button5,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led5,GPIO.OUT)
GPIO.setup(button6,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led6,GPIO.OUT)
GPIO.setup(button7,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led7,GPIO.OUT)
GPIO.setup(button8,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led8,GPIO.OUT)
GPIO.setup(button9,pull_up_down=GPIO.PUD_UP)
GPIO.setup(led9,GPIO.OUT)
#my functions to play videos
def playVid1(ev=None):
print('Button 1 pressed...')
player = True
while player == True:
omxc = Popen(['omxplayer','-b',movie1])
GPIO.output(led1,True)
time.sleep(15.0)
print('Button 1 after...')
GPIO.output(led1,False)
player = False
def playVid2(ev=None):
print("video2 is playing")
def playVid3(ev=None):
print("video3 is playing")
def playVid4(ev=None):
print("video4 is playing")
def playVid5(ev=None):
print("video5 is playing")
def playVid6(ev=None):
print("video6 is playing")
def playVid7(ev=None):
print("video7 is playing")
def playVid8(ev=None):
print("video8 is playing")
def playVid9(ev=None):
print("video9 is playing")
#the "mainloop"
def loop():
GPIO.output(led1,False) #sets led off
GPIO.output(led2,False)
GPIO.output(led3,False)
GPIO.output(led4,False)
GPIO.output(led5,False)
GPIO.output(led6,False)
GPIO.output(led7,False)
GPIO.output(led8,False)
GPIO.output(led9,False)
GPIO.add_event_detect(button1,GPIO.FALLING,callback=playVid1,bouncetime=200)
print("it still loops")
GPIO.add_event_detect(button2,callback=playVid2,bouncetime=200)
GPIO.add_event_detect(button3,callback=playVid3,bouncetime=200)
GPIO.add_event_detect(button4,callback=playVid4,bouncetime=200)
GPIO.add_event_detect(button5,callback=playVid5,bouncetime=200)
GPIO.add_event_detect(button6,callback=playVid6,bouncetime=200)
GPIO.add_event_detect(button7,callback=playVid7,bouncetime=200)
GPIO.add_event_detect(button8,callback=playVid8,bouncetime=200)
GPIO.add_event_detect(button9,callback=playVid9,bouncetime=200)
def endprogram():
GPIO.output(led1,GPIO.HIGH) #led off
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
print( 'keyboard interrupt detected' )
endprogram()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)