Python:使用OMXplayer在后台播放音频

Python:使用OMXplayer在后台播放音频,python,audio,video,raspberry-pi,omxplayer,Python,Audio,Video,Raspberry Pi,Omxplayer,我目前正在做一个项目,其中包括启动一个视频,立即暂停它,然后在给定的事件之后启动它。(万圣节计划:什么也没发生,如果有人经过,吓一跳) 但我似乎无法将音频设置为与视频同时播放(当事件触发时),音频总是在开始时播放 有人能解决这个问题吗 bla bla bla ... # Declaration face_walking_apparition_time = 0 music_apparition_time = 0 walking_timer = time.time() music_timer =

我目前正在做一个项目,其中包括启动一个视频,立即暂停它,然后在给定的事件之后启动它。(万圣节计划:什么也没发生,如果有人经过,吓一跳)

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

有人能解决这个问题吗

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)
blablablabla。。。
#声明
脸\u行走\u幻影\u时间=0
音乐\u幻影\u时间=0
行走计时器=time.time()
音乐计时器=time.time()
最后一次行走的街区=无
files1=“Madam_Old_H.mp4”
audio1=“尖叫女人。mp3”
#屏幕大小
长度='1366'
swidth='768'
打印(“启动…”)
tgr=0
尝试:
#----视频-----
视频路径=路径(文件1)
音频路径=路径(音频1)
player=OMXPlayer(视频路径,args=['-no-osd','-loop','-win',0{0}{1}'。格式(slength,swidth)])
audio=OMXPlayer(audio_路径,args=['--no-osd','--loop']))
时间。睡眠(1)
#打印(“准备触发”)
尽管如此:
#暂停视频
player.pause()
audio.pause()
GPIO.setup(11,GPIO.OUT)
#清理输出
GPIO.输出(11,0)
睡眠时间(0.000002)
#发送信号
GPIO.输出(11,1)
睡眠时间(0.000005)
GPIO.输出(11,0)
GPIO.setup(11,GPIO.IN)
#测量距离
当GPIO.input(11)==0时:
开始=时间。时间()
当GPIO.input(11)==1时:
停止=时间。时间()
打印(“测量”)
持续时间=停止-启动
距离=持续时间*34000/2
DD=圆形(距离)
印刷品(DD,“cm”)
睡眠时间(0.5)
blocks=hl.requestAll()#块和箭头
如果(20030:#如果检测到块超过30秒
player.play()
audio.pause()
time.sleep(player.duration())
如果面部\u行走\u幻影\u时间>50:
player.pause()
行走计时器=time.time()
脸\u行走\u幻影\u时间=0
elif(50
我想澄清一下,我是python新手,目前正在使用RaspBerry Pi 3