0

So my question is about how to control omxplayer remotely using netcat (nc) or simple TCP. Do I need to use named pipes and if so what are the commands needed. There are many way to accomplish what I want but i need a simple approach. I know that i can use ssh and screen as well so any way would work. I'm just messing around so i can play movies in the rpi. I already coded the same for mplayer using python while using subprocess library!

Update with info from comments:
It could work by running an omxplayer instance with input redirection to a named pipe.. After that running netcat as a server and writing to that named pipe. Another option would be using omxplayer inside a screen session and send input over ssh sending input directly to that omxplayer screen session.. But what I read is that omxplayer doesnt accept keyboard input directly to the shell.. If so then the next option would be using uinput or another way to send virtual keyboard input to the running omxplayer video playing window !! ?

sudo apt-get install xautomation

Home
Left
Up
Right
Down
Page_Up
Page_Down
End
Return
BackSpace
Tab
Escape
Delete
Shift_L
Shift_R
Control_L
Control_R
Meta_L
Meta_R
Alt_L
Alt_R
Multi_key  
Super_L  
Super_R

xte 'key Left'

The same can be done with xdotool

sudo apt-get install xdotool
xdotool search --class Omxplayer

Note that the class name can be another one or just search by name in case focus belongs to another window. We can use wmctrl to find the specific window ID as well and then focusing on it

# wmctrl -l | grep 'omxplayer'
# wmctrl -a 'omxplayer'

OmxplayerID=$(xdotool search --name omxplayer | head -1)

netcat -lk -p 12345 | while read keystroke
do
    match=$(echo $keystroke | grep -c 'Kill')

    if [ $match -eq 1 ]; then
        echo "End Media Playback Then Exit"
    else
        xdotool windowactivate --sync $OmxplayerID key $keystroke
    fi
done

Client:

# xev | awk -F'[ )]+' '/^KeyPress/ { a[NR+2] } NR in a { printf "%-3s %s\n", $5, $8 }'

xev -event keyboard | while read DetectKeystroke
do
    echo $DetectKeystroke
    # send over the network usimg netcat tcp/udp
    # nc & netcat its the same thing
    nc localhost -p 12345 $DetectKeystroke 

done

If the only way is over virtual keyboard then it is already solved.. Since i don't have a keyboard with me right now i cant write a working code or even test code. I'm resorting to a mouse and open office inserting characters one by one until i write a line of code... Not fun!

Thanks you all for your time :)

  • How do you think it could work using netcat? Do you have a vague idea, maybe some pseudo code? – Ingo Aug 1 at 21:36
  • Well running an omxplayer instance with input redirection to a named pipe.. After that running netcat as a server and writing to that named pipe. Another option would be using omxplayer inside a screen session and send input over ssh sending input directly to that omxplayer screen session.. But what I read is that omxplayer doesnt accept keyboard input directly to the shell.. If so then the next option would be using uinput or another way to send virtual keyboard input to the running omxplayer video playing window !! ? – DarkXDroid Aug 3 at 1:07
  • * sudo apt-get install xautomation ; xte 'key Left' * – DarkXDroid Aug 3 at 1:34
  • The same can be done with xdotool – DarkXDroid Aug 3 at 1:39
  • If the only way is over virtual keyboard then it is already solved.. Since i don't have a keyboard with me right now i cant write a working code or even test code. I'm resorting to a mouse and open office inserting characters one by one until i write a line of code... Not fun! – DarkXDroid Aug 3 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.