How can I know the if a video is playing in python?

Refresh

6 days ago

Views

14 time

0

I am trying to make a video player that runs a set of standby videos until a distance sensor sees something below a certain distance, at which point, a video is played in it's entirety . so far this is what I got:

def videowakeup(): #video for when the sensor detects
    screen=pygame.display.set_mode((320,240))
    screen.fill((0,0,0))
    os.system("sudo killall -s 9 omxplayer.bin")
    playProcess = subprocess.Popen(['omxplayer','-b','/home/pi/Videos/SquidwardSickomode.mp4'], stdout=subprocess.PIPE, preexec_fn=os.setsid)

#define vars
movies = ["revolving.mp4","ocelot.mp4","FreddieFreaker.mp4"]
playingmovie = "/home/pi/Videos/"+movies[0]
currentmovie = 0
loopcount = 0

#MAIN LOOP 
while loopcount < 20: #for debugging reasons 
    perto1 = distance()
    print(perto1)
    if perto1 < 50:
#here I would place a condition that checked if the video is playing
        videowakeup()
        loopcount += 1
    else:
        #video for when the sensor doesnt detect
        playingmovie = "/home/pi/Videos/"+movies[currentmovie]
        playProcess=subprocess.Popen(['omxplayer','-b',playingmovie], stdout=subprocess.PIPE, preexec_fn=os.setsid)
        currentmovie += 1
    loopcount += 1
    print(loopcount)
    time.sleep(0.1)
    if currentmovie == len(movies):currentmovie = 0
    pass

my problem right now is that it plays every video at virtualy the same time, though I think I could fix it if there was someway to check for a playing video.

0 answers