我有一个简单的项目,我想结合运动传感器来播放某些视频文件。所以通常在不定式循环中,我想播放一个闪烁的视频,如果触发了运动传感器,我想停止闪烁的视频并选择一个可怕的视频。请参阅以下代码。
import RPi.GPIO as GPIO
import time
from omxplayer.player import OMXPlayer
from random import randint
#
def main():
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN)
flicks = ("/home/pi/halloween/flicks/tv_noise_1.mp4")
scares = ("/home/pi/halloween/scares/tv_noise_kitten_zombie_2.mp4")
omxc = OMXPlayer(flicks)
state = 0 # set initial state as 0
while True:
i = GPIO.input(17)
if(not omxc.is_playing()):
omxc = OMXPlayer(flicks)
if(state != i): # change in state detected
omxc.quit()
omxc = OMXPlayer(scares)
time.sleep(35) # wait as long as this video lasts
state = i
if __name__ == '__main__':
main()
但是,我不断收到错误消息:
Traceback (most recent call last):
File "scare_old.py", line 29, in <module>
main()
File "scare_old.py", line 20, in main
if(not omxc.is_playing()):
File "<decorator-gen-90>", line 2, in is_playing
File "/home/pi/.local/lib/python2.7/site-packages/omxplayer/player.py", line 48, in wrapped
raise OMXPlayerDeadError('Process is no longer alive, can\'t run command')
omxplayer.player.OMXPlayerDeadError: Process is no longer alive, can't run command
究竟是什么问题?我的意思是该过程应该运行,因为我刚刚开始它?