Python:带有 OMXplayer 的背景音频

问题描述

我目前正在开展一个项目,该项目涉及启动视频、立即暂停以及在特定事件后启动视频。 (万圣节项目:什么都没有发生,如果有人经过,吓一跳)

但我似乎无法将音频设置为与视频同时播放(当事件触发时),音频总是在开头播放。

有没有人有解决方案?

bla bla bla ...

# Declaration
face_walking_apparition_time = 0
music_apparition_time = 0
walking_timer = time.time()
music_timer = time.time()
last_walking_block_seen = None
files1 = "Madam_Old_H.mp4"
audio1 = "Scream_Woman.mp3"
# Screen size
slength = '1366'
swidth = '768'
print("Starting up ...")
tgr = 0

try:
    # ----- VIDEO -----
    VIDEO_PATH = Path(files1)
    AUdio_PATH = Path(audio1)
    player = OMXPlayer(VIDEO_PATH,args = ['--no-osd','--loop','--win','0 0 {0} {1}'.format(slength,swidth)])
    audio = OMXPlayer(AUdio_PATH,'--loop'])
    time.sleep(1)
    #print("Ready to trigger")   

    while True:

        # Pause the video
        player.pause()
        audio.pause()

        GPIO.setup(11,GPIO.OUT)

        # Cleanup output
        GPIO.output(11,0)
        time.sleep(0.000002)

        # Send signal
        GPIO.output(11,1)
        time.sleep(0.000005)
        GPIO.output(11,0)
        GPIO.setup(11,GPIO.IN)

        # Measure the distance
        while GPIO.input(11) == 0:
            start = time.time()

        while GPIO.input(11) == 1:
            stop = time.time()

        print("Measuring")

        duration = stop - start
        distance = duration * 34000 / 2
        DD = round(distance)
        print(DD,"cm")
        time.sleep(0.5)

        blocks = hl.requestAll() # Blocks and Arrows

        if(200 < DD): # If we are more than 200 cm away
            # We count the number of seconds between the last checkpoint and Now
            face_walking_apparition_time = time.time() - walking_timer # (t+3) - t = 3,it's how u calculate timer
            print(face_walking_apparition_time)
                    
            # Then we check if a face has appeared for more than 30 seconds:
            if face_walking_apparition_time > 30: # If the block is detected more than 30 seconds
                player.play()
                audio.pause()
                time.sleep(player.duration())
            if face_walking_apparition_time > 50:
                player.pause()
                walking_timer = time.time()
                face_walking_apparition_time = 0
                
        elif (50 < DD) and (DD < 200):
            # As we don't see no face,we have to reset our checkpoint to "Now"
            walking_timer = time.time()
            music_timer = time.time()
            face__walking_apparition_time = 0
            music_apparition_time = 0
            time.sleep(0.1)

我想澄清一下,我是 Python 新手,并且我目前使用的是 RaspBerry Pi 3

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...