parser = argparse.ArgumentParser()
parser.add_argument('--shuffle', '-s', action='store_true', default=False)
args = parser.parse_args()
#extract mp4 files from current folder
from glob import glob
files = glob('*.mp4')
#play each file in omxplayer:
for f in files:
os.system('omxplayer -o local "%s"' % f)
#exit on ctrl+c (does not work, as ctrl+c is captured by omxplayer...)
I’m trying to make omxplayer just play 1 video out of the folder randomly and then stop but it keeps going through all of the videos in the folder I thought
os.system('killall omxplayer.bin') '''
would stop it but it doesn’t, Any help is greatly appreciated
os.system() runs the program “on the foreground”. This means that the python process waits (automatically in the
os.system() function) until the program finishes.
I do not understand how you want to recognize that the first video finished. The code below will let
omxplayer running for 20 seconds then it asks it to terminate. Termination may not work if
omxplayer spawns its own sub-processes. Also if you need to use
omxplayer you would need a little bit more complex code.
for file in files:
process_omxplayer = subprocess.Popen(
('omxplayer', '-o', 'local', file),
If the process does not terminate on signal 15, you can try signal 9:
You do not need to catch
KeyboardInterrupt. This exception terminates a python program also if you do not handle it. When you have a sub-process on foreground ignoring
SIGINT (Ctrl+c) then catching the exception will not help.
By Václav Brožík via Discussions on Python.org at 09Jun2022 20:32:
You do not need to catch
KeyboardInterrupt. This exception terminates
a python program also if you do not handle it. When you have a
sub-process on foreground ignoring
SIGINT (Ctrl+c) then catching the
exception will not help.
This isn’t entirely true. You could:
SIGINT and kill
pid if not
- dispatch the external programme and not wait for it, record the pid in
SIGINT after the external programme returns
Untested, but seems ok. It won’t work if the external programme actually
disables the terminal setting causing
^C to send
SIGINT, but that is
very rare - more likely the external programme itself simple catches and
KeyboardInterrupt exception presumably simply does not fire during
os.system. Also untested. And not necessarily true, just based on the
OP’s code not working that way.
Cameron Simpson email@example.com
Yea it needs to be the exact time of the video since the videos have different lengths, with I could just use a sort -r