我对 Python 有点陌生,我正在为连接运动传感器的 Raspberry Pi 开发一个应用程序。 这个想法是把这个 Raspberry 放在一个房间里,在运动检测时,视频开始全屏播放。 视频播放完毕后,我想让设备休眠 10 分钟,然后再次激活运动传感器以再次播放相同的视频。视频结束后屏幕也应该保持黑色,因此不要退出 vlc 应用程序并查看 Raspberry Pi 桌面。
到目前为止,我尝试了一些代码,其中一个文件中全屏工作,而另一个文件中循环工作,但是将两个文件放在一起会出现错误。
正如我所说,我对编码非常陌生,所以问题可能非常愚蠢,解决方案非常简单。先谢谢您的帮助。 在我的 2 个代码文件下面。
选项 1(全屏不起作用)
from gpiozero import MotionSensor, LED
from time import sleep
import vlc
# creating Instance class object
player = vlc.Instance()
# creating a new media list
media_list = player.media_list_new()
# creating a media player object
media_player = player.media_list_player_new()
# creating a new media
media = player.media_new("/home/pi/MOSA25.mp4")
# adding media to media list
media_list.add_media(media)
# setting media list to the mediaplayer
media_player.set_media_list(media_list)
# setting loop
player.vlm_set_loop("1", True)
#fullscreen
#media_player.set_fullscreen(True)
#Motion Sensor
pir = MotionSensor(4)
#Led
led = LED(26)
led.off()
print("Sensor loading.")
pir.wait_for_no_motion()
sleep(5)
while True:
print("Ready")
pir.wait_for_motion()
print("Motion detected")
led.on()
sleep(5)
led.off()
media_player.play()
sleep(30)
选项 2(循环不起作用)
from gpiozero import MotionSensor, LED
from time import sleep
import vlc
# creating Instance class object
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
player.set_mrl("/home/pi/MOSA25.mp4")
player.set_fullscreen(True)
# setting loop
#player.vlm_set_loop("1", True)
#Motion Sensor
pir = MotionSensor(4)
#Led
led = LED(26)
led.off()
print("Sensor wordt geladen.")
pir.wait_for_no_motion()
sleep(5)
while True:
print("Ready")
pir.wait_for_motion()
print("Motion detected")
led.on()
sleep(5)
led.off()
player.play()
sleep(20)
跟踪另一个
while
循环播放的视频并在重新开始之前重新加载。from time import sleep
import vlc
playing = set([1,2,3,4])
# creating Instance class object
vlc_instance = vlc.Instance()
player = vlc_instance.media_player_new()
player.set_fullscreen(True)
#Motion Sensor
#pir = MotionSensor(4)
#Led
#led = LED(26)
#led.off()
print("Sensor wordt geladen.")
#pir.wait_for_no_motion()
sleep(5)
while True:
print("Ready")
# pir.wait_for_motion()
sleep(1)
print("Motion detected")
# led.on()
sleep(1)
# led.off()
player.set_mrl("/home/pi/MOSA25.mp4")
player.play()
sleep(1)
while player.get_state() in playing:
sleep(1)
continue
print("Finished")
sleep(5)
continue
@GraphicNilez 多么伟大的项目啊!我正在玩同一个项目。您现在使用的代码是什么?可以分享一下代码吗