在Python中是否可以基于时间控制OMXplayer?

在Python中是否可以基于时间控制OMXplayer?,python,raspberry-pi3,dbus,omxplayer,Python,Raspberry Pi3,Dbus,Omxplayer,我试图在使用Python脚本播放视频期间控制OMXplayer。我是Python方面的Dbus新手,希望只是缺少一些简单的东西 最终我想用一个使用GPIO引脚的运动传感器来实现这一点,但首先我只是想控制播放器。我需要做的是在一段时间内循环播放一段视频,然后在视频中断时跳转到“第二段”。我正在使用一个键条目来测试它 我的问题是代码中的“if”语句不会循环,除非输入的键或任何其他信号中断。任何键都会导致中断,但我希望循环中特定于时间的“if”语句在不输入任何输入的情况下触发。我希望我所说的在下面的代

我试图在使用Python脚本播放视频期间控制OMXplayer。我是Python方面的Dbus新手,希望只是缺少一些简单的东西

最终我想用一个使用GPIO引脚的运动传感器来实现这一点,但首先我只是想控制播放器。我需要做的是在一段时间内循环播放一段视频,然后在视频中断时跳转到“第二段”。我正在使用一个键条目来测试它

我的问题是代码中的“if”语句不会循环,除非输入的键或任何其他信号中断。任何键都会导致中断,但我希望循环中特定于时间的“if”语句在不输入任何输入的情况下触发。我希望我所说的在下面的代码中是清楚的,但如果没有,请提出任何问题,我很乐意尝试澄清

我正在使用Will Price的OMXplayer包装器:

我的硬件是树莓皮3B+

我看过类似的问题,包括以下问题,但没有找到答案:

我已经清除了代码中不必要的部分,所以这是一个基本的功能版本

from omxplayer.player import OMXPlayer #runs from the popcornmix omxplayer wrapper at https://github.com/popcornmix/omxplayerhttps://github.com/popcornmix/omxplayer and https://python-omxplayer-wrapper.readthedocs.io/en/latest/)
from pathlib import Path
import time
import RPi.GPIO as GPIO #for taking signal from GPIO
import subprocess
import logging
logging.basicConfig(level=logging.INFO)

VIDEO_PATH = Path("VIDEO.m4v")
player_log = logging.getLogger("Player 1")

player = OMXPlayer(VIDEO_PATH, dbus_name='org.mpris.MediaPlayer2.omxplayer1')
player.playEvent += lambda _: player_log.info("Play")
player.pauseEvent += lambda _: player_log.info("Pause")
player.stopEvent += lambda _: player_log.info("Stop")

positionEvent = 12
flyin = 3
flyaway = 15

'''
THE ERROR OCCURS IN THE BELOW FUNCTION!!!
the following function does not run each time
the 'while' loop below is playing, but does run
when there is a key pressed as an 'input'

I want to add a chck so that each time a certain
amount of time passes, the video jumps back
'''
def checktime():
    currtime = player.position()
    print("current time is " + str(currtime))

    if(currtime > 3):
        print("currtime is greater than 3")


try:

    player.play()

    print ("  Ready")

    while True:

        '''
        Below is the call for the function 'checktime'
        This runs once when the video starts, and only
        runs again when a key is entered.
        I want this to run on a continuous loop
        and call each time the video loops
        '''
        checktime()

        key = input()

        if key == 'd': #works perfectly
            currtime = player.position()
            player.seek(flyin-currtime)
            print("player position is" + str(player.position()))

        if key == 'a': #works perfectly
            currtime = player.position()
            player.seek(flyaway-currtime)

        if key == 's': #works perfectly
            player.play()

        '''
        in addition to the key inputs above, entering any key
        and pressing return will run the checktime()
        function. I understand that this is receiving an
        input, therefore 'waking' the program up,
        but I don't understand why the loop is not working
        continuously
        '''


        # Wait for 10 milliseconds
        time.sleep(.01)


except KeyboardInterrupt:
  print ("  Quit")
  # Reset GPIO settings
  GPIO.cleanup()


视频是使用“s”、“a”和“d”键作为输入进行控制的,这一点非常有效。但是,“checktime()”函数不会在每次while循环运行时调用。我的猜测是,这是因为一旦视频播放,它不会从Python程序中寻找任何东西,直到它收到另一个输入

我不确定是否正确使用了DBus。理想情况下,我想使用omxplayer包装器的seek_absolute函数,但我一直无法理解这一点。我一直在努力推进这个项目,自从发布了一个早期的问题(见这里:)以来,我对这个项目有了更好的理解,但我在这里有点困惑

如果有人能帮助我,我将感谢任何建议