0

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

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

有人对此有解决方案吗?

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, args = ['--no-osd', '--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

4

0 回答 0