I have a python script that allows me to interact with my Rapsberry Pi from my phone using a simple web server (Flask).
In this script, I can call omxplayer to play a media file, I do this via a command like this:
Popen(['omxplayer '+filePath], shell=True, stdin=None, stdout=None, stderr=None, close_fds=True) This works fine but then I would like to be able to interact with this process by sending key commands. When omxplayer is running, you can press space to play/pause, arrows to skip forward/back, etc. I would like to send these keyboard inputs programatically from my python script instead of requiring a person to manually press them on the keyboard.
How can I send a key command to this process from Python after opening it with Python?
Also, how can I detect from Python if there is another instance of omxplayer running that is not being currently run from this Python script? For example, if omxplayer was called and is running from someone on an ssh connection, how can I detect this inside the python script and kill this process before calling my own omxplayer process?