Python Forum

Full Version: for loop just work one
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys. I have a python script for run omxplayer. My purpose this: I have four .mp4 file. I want run these one by one. This fr loop in my script just work one time. How can I fix this?
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import glob
import os 
import subprocess

videolist=[]
uzunluk=0
video_no=[]

videolist=glob.glob('/media/pi/FLASH/playlist/*.mp4')
videolist=videolist+glob.glob('/media/pi/FLASH/playlist/*.MP4')

uzunluk=len(videolist)
for i in xrange(0,uzunluk,1):
    videoproc=subprocess.Popen(['omxplayer','--win', '0,440,480,800', videolist[i]],stdin=subprocess.PIPE, shell=False)
    print videolist[i]

I solved problem. Just wait subprocess until finish.
untested:
remove line 15-18 and change line 16 to:
for video in videolist:
    videoproc=subprocess.Popen(['omxplayer','--win', '0,440,480,800', video, stdin=subprocess.PIPE, shell=False)
    print video
but my guess is that this is going to play all three without delay.
since you are running as sub-process, you need to store running time in list (use tuples or embedded list), like: videolist = [[time, mp4],[time, mp4]]) and delay between submissions.