paulie420 wrote to All <=-
# Setup Randon Videos
videoPath = "/home/pi/Videos/"
videoList = os.listdir(videoPath)
random.shuffle(videoList)
for video in videoList:
target = os.path.join(videoPath, video)
# Wait for button press
print("Waiting for button press to start video.")
button.wait_for_active()
os.system('omxplayer --aspect-mode stretch "{}" > /dev/null'.format(target))
#subprocess.Popen('omxplayer --acpect-mode stretch "{}" > /dev/null'.format(target))
but #didnt work YET. The os.system does play a video... just waits
there before #listening again for a button press.
Not part of your question, but I don't see the reason to get the video list all the time, then go through the video list to get the last one to play.
I suggest putting this code outside the While loop. Then when the
button is pressed, just pick a random number and play the video at that location in the list of videos.
os.system runs a command, then waits for it to complete before
continuing.
So, if you want the button to be deactivated while the video is playing, then os.system is the way to go.
subprocess.Popen is used to execute a process, but makes it easier for
you to communicate with the subprocess. But it also allows you to run
the process in the "background" (i.e. once you run it, it returns immediately - but now you have to manage the process, poll it periodically, etc.)
IHMO, unless you are already very familiar with Linux and subproceses, I suggest
that you do not use this.
but #didnt work YET. The os.system does play a video... just waits there before #listening again for a button press.
Then the issue is with omxplayer. It's not exiting when it's done
playing the video.
paulie420 wrote to Dr. What <=-
Well, ok... I might have to learn about subprocesses; because the subprocess.Popen sounds like the way to go. Also, sounds like by
polling and whatnot I could pass further commands to omxplayer WHILE
the video is running. (Like q, quit, fastforward, etcetc...)
Sysop: | Saxainden |
---|---|
Location: | Littleton, CO |
Users: | 30 |
Nodes: | 10 (0 / 10) |
Uptime: | 06:03:52 |
Calls: | 350 |
Messages: | 36,671 |