0

So I have a loop executing video files on VLC. I want to make an executable file (.bat or .py I don't care) for running this code

for video in list:
   subprocess.run([vlc,'--play-and-exit','-f', video], shell=True)

I want the user to be able to interrupt this without ctrl+C (which only works if vlc is closed which also is a problem, because it is only closed for like 0.1 seconds)

I tried with a flag controlled by a button, but it does not work because vlc must be closed to control the flag (same problem as ctrl+c)

for video in list:
       subprocess.run([vlc,'--play-and-exit','-f', video], shell=True)
       if flag: 
          break

I don't want to close the program window to stop running the program

arioman
  • 29
  • 3
  • 1
    "I want the user to be able to interrupt this without ctrl+C" How will the user do this? And more importantly, *what should happen* if the user tries to interrupt while vlc is in the middle of a video? – Karl Knechtel Nov 27 '20 at 20:45
  • I don't know how the user will do that (maybe a button?). If the user interrupts in the middle of a video, the video must go on until finished – arioman Nov 28 '20 at 00:06

1 Answers1

1

I used Popen instead of subprocess, so the video process starts in background, continuing with python code.

Then I looked for a function that returns 1 if Enter is pressed, if not waits 1 second and returns 0.

process = Popen([vlc,'--play-and-exit','-f', video])
                            while process.poll() is None:
                                    flag = readInput(text, False, 1)                                         
                                    if flag:
                                            break

the function readinput() was found here Keyboard input with timeout?

arioman
  • 29
  • 3