我在用Python创建的视频循环中遇到了一些麻烦。我想要做的是播放视频循环,然后当按下按钮(RPi GPIO)时,它将播放不同的视频。一旦该视频播放完毕,它应该返回播放循环播放的视频。除了在其他正在播放的视频播放之前,循环视频将开始播放之前,以下代码一切都很好。我不确定是否这是一个问题,我如何做循环或如果我需要暂停子进程。如何暂停一个子进程(Python 2.2.6)?
非常感谢你们提供的任何帮助和建议!
#!/usr/bin/python
from time import sleep
import RPi.GPIO as GPIO
import subprocess
import time
import thread
GPIO.setmode (GPIO.BCM)
GPIO.setwarnings (False)
GPIO.setup(9, GPIO.IN)
GPIO.setup(10, GPIO.IN)
GPIO.setup(11, GPIO.IN)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(22, GPIO.OUT)
GPIO.setup(27, GPIO.OUT)
def welcome_loop():
while True:
global playProcess
x = 1
print "Play Welcome Video"
time.sleep(.5)
playProcess=subprocess.Popen(['omxplayer','-b','Desktop/videos/loop/loop.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
time.sleep(25)
x += 1
def videos():
while True:
if GPIO.input(9):
print "Stop Welcome Video"
time.sleep(.5)
playProcess.stdin.write('q')
time.sleep(.5)
print "Play Sippycup Video"
sippycup_video=subprocess.Popen(['omxplayer','-b','Desktop/videos/sippycup.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
time.sleep(30)
sippycup_video.stdin.write('q')
time.sleep(.5)
#welcome_loop()
if GPIO.input(10):
print "Stop Welcome Video"
time.sleep(.5)
playProcess.stdin.write('q')
time.sleep(.5)
print "Play Shoppingcart Video"
shoppingcart_video=subprocess.Popen(['omxplayer','-b','Desktop/videos/shoppingcart.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
time.sleep(30)
shoppingcart_video.stdin.write('q')
time.sleep(.5)
#welcome_loop()
if GPIO.input(11):
print "Stop Welcome Video"
time.sleep(.5)
playProcess.stdin.write('q')
time.sleep(.5)
print "Play Dodgeballs Video"
Dodgeballs_video=subprocess.Popen(['omxplayer','-b','Desktop/videos/dodgeballs.mp4'],stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,close_fds=True)
time.sleep(30)
Dodgeballs_video.stdin.write('q')
time.sleep(.5)
#welcome_loop()
thread.start_new_thread(videos,())
thread.start_new_thread(welcome_loop,())
while True:
pass
GPIO.cleanup()
哦蟒蛇2.2.6 ... – Anzel 2014-10-27 15:49:43