Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for loop just work one
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  While Loop Does Not Work Properly mactron 4 912 Jun-22-2023, 01:04 AM
Last Post: mactron
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,011 Dec-18-2021, 02:38 AM
Last Post: knight2000
  How can this for loop work without : ? Pedroski55 1 1,694 Dec-13-2020, 01:19 AM
Last Post: palladium
  Please help my while loop does not work as expected KingKhan248 6 2,619 Sep-28-2020, 09:12 PM
Last Post: deanhystad
  For loop in my __init__ doesn't work as expected Jessy 2 2,361 Nov-18-2019, 10:07 AM
Last Post: buran
Question Why does modifying a list in a for loop not seem to work? umut3806 2 2,293 Jul-22-2019, 08:25 PM
Last Post: umut3806
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 3,195 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  'Looping' does not work out within a 'for Loop' Placebo 4 3,336 Sep-15-2018, 08:19 PM
Last Post: Placebo
  Having issues getting a loop to work PLESSE HELP ASAP manthus007 1 2,115 Aug-25-2018, 10:44 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020