Wednesday, September 11, 2013

gnome-mplayer remote with qt and libssh2

This is project I've created some time ago for gnome-mplayer remote control. It uses qt as a GUI, libssh2 for ssh communication and dbus to control the player.

The plan was to put all those peaces together and make a remote control for this media player. I started a project, which you can find here: https://bitbucket.org/nchokoev/qtsshremote.

The remote control uses dbus commands over ssh to control the gnome-mplayer.

First thing is to connect to the host and establish ssh connection and get ansi terminal. It's nice to use a terminal as we can see when the command is completed. For this I'm using a little trick - I'm changing the prompt string. Once I receive this string I know the command is executed.

The first command is to set the xorg display environment variable:
"export DISPLAY=:0\n"

To check if there is gnome-mplayer running I'm using the following code. It checks the running processes for 'gnome-mplayer' and gets their PIDs.
"pgrep gnome-mplayer\n"

Setting DBUS_SESSION_BUS_ADDRESS:
QString s = "$(tr '\' '\\n' < /proc/$(pgrep gnome-mplayer | head -1 )/environ | sed -e 's/^/export /')\n";
  execSSHCmd((char*)s.toUtf8().constData(),s.size(), buf, 0);
s = "echo $DBUS_SESSION_BUS_ADDRESS\n";
  execSSHCmd((char*)s.toUtf8().constData(),s.size(), buf, 0);

To get the files and folders I'm using 'ls' command. The only difference is that I force the output to be an entry per line (-1) and no colours (--color=none). It makes much easier the output parsing.
"ls -1 --color=none\n"

The other part of the code is pretty straight forward. It uses the gnome-mplayer dbus messages to control the player.

The nice thing is that it is very easy to open and close the player as well as navigate the the desired media file and play it.

You can download the code and use it without any restrictions. However, I'll appreciate if you leave a feedback or if you send me any modifications you've made.

I hope you find it useful.

Subscribe for our NewsLetter!

4 comments:

  1. I downloaded source and i tried build it, but i have some issues. Could you give me some advice how i should build this project?

    ReplyDelete
  2. Did you get the libssh2 as well? What kind of issues you have?

    ReplyDelete
  3. hi i'm tring your code on mac sierra and linux ubuntu 16 (as client and server).
    I allways get

    No protocol specified
    Failed to connect to Mir: Failed to connect to server socket: No such file or directory
    Unable to init server: Could not connect: Connection refused

    (gnome-mplayer:3707): Gtk-WARNING **: cannot open display: :0

    have an idea?

    ReplyDelete
    Replies
    1. Did you try:
      https://www.linuxquestions.org/questions/debian-26/gtk-warning-**-cannot-open-display-0-0-a-807450/

      Delete