Python VLC 实例全屏不工作

Python VLC Instance Fullscreen not working

我对 Python 有点陌生,我正在为连接了运动传感器的 Raspberry Pi 开发应用程序。 这个想法是将这个 Raspberry 放在一个房间里,并在运动检测时开始全屏播放视频。 视频播放完毕后,我想让设备休眠 10 分钟,然后再次激活运动传感器以再次播放同一视频。屏幕也应该在视频结束后保持黑色,所以不要退出 vlc 应用程序并查看 Raspberry Pi 桌面。

到目前为止,我尝试了一些代码,在其中一个文件中全屏有效,而在另一个文件中循环有效,但是将 2 个文件放在一起会出错。

正如我所说,我对编码很陌生,所以问题可能很愚蠢,解决方案也很简单。先谢谢您的帮助。 在我的 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