我在用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