Sending keys to omxplayer
Posted: Wed Nov 13, 2013 11:16 pm
I think I need to do something with pipes here but I am not familiar with the process. I'm looking for a way to send signals or key presses to a process (specifically omxplayer) and I can't piece it all together. The "TODO" comments below show what I am trying to accomplish. Video playback works. I get valid PIDs. I just don't know how to control omxplayer once the process has started. Any help? Thanks in advance.
Code: Select all
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(void){
int pidChild;
int pidParent;
int pid = fork();
if(pid == 0){
pidChild = getpid();
cout << "Child PID: " << pidChild << endl;
execlp("/usr/bin/omxplayer", "-r ", "/mnt/disk1/Videos/002.mp4", NULL);
//TODO: Send 'spacebar' to Omxplayer to pause playback
cout << "Playback loaded" << endl;
_exit(0);
}
else{
pidParent = getpid();
cout << "Parent PID: " << pidParent << endl;
//wait();
}
//External events occur here, simulate with sleep
sleep(5);
//TODO: Send 'spacebar' to Omxplayer to start playback
cout << "Playback start" << endl;
//External events occur here, simulate with sleep
sleep(5);
//TODO: Send 'q' or kill omxplayer
cout << "Playback end" << endl;
}