私は長い道のりを歩んできました、そして私はほとんどそこにいます。Thread の使用から Threading の使用に切り替え、再生中にビデオを切り替えることができるようになりましたが、最初のビデオを強制終了または停止するのにまだ問題があります。基本的に、OMXplayer を使用して Raspberry Pi のボタンで制御されるビデオ プレーヤーを作成しています。現時点では、別のボタンを押す前に 1 つのビデオの再生が終了するのを待たなければなりません。そうしないと、複数のビデオが同時に再生されてクラッシュします。
皆さんが提供できるあらゆる助けに感謝します。
#!/usr/bin/python
import RPi.GPIO as GPIO
import subprocess
import threading
import time
GPIO.setmode (GPIO.BCM)
GPIO.setwarnings (False)
GPIO.setup(9, GPIO.IN) # Button 1
GPIO.setup(10, GPIO.IN) # Button 2
def shoppingcart():
global current_video
while True:
if GPIO.input(9):
#current_video.terminate()
#current_video.kill()
print "Play Shoppingcart"
time.sleep(1)
current_video=subprocess.Popen(['omxplayer','-b','Desktop/videos/shoppingcart.mp4'],
stdin=subprocess.PIPE,stdout=subprocess.PIPE,
stderr=subprocess.PIPE,close_fds=True)
def dodgeballs():
global current_video
while True:
if GPIO.input(10):
#current_video.terminate()
#current_video.kill()
print "Play Dodgeballs"
time.sleep(1)
current_video=subprocess.Popen(['omxplayer','-b','Desktop/videos/dodgeballs.mp4'],
stdin=subprocess.PIPE,stdout=subprocess.PIPE,
stderr=subprocess.PIPE,close_fds=True)
v1 = threading.Thread( name='shoppingcart', target=shoppingcart ) # Videos thread
v2 = threading.Thread( name='dodgeballs', target=dodgeballs ) # Videos thread
v1.start()
v2.start()
while True:
pass
GPIO.cleanup() #Reset GPIOs