Skip to content

Instantly share code, notes, and snippets.

@melvyniandrag
Created April 10, 2018 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvyniandrag/6b1f562e9bb24b360b13ff48defc2608 to your computer and use it in GitHub Desktop.
Save melvyniandrag/6b1f562e9bb24b360b13ff48defc2608 to your computer and use it in GitHub Desktop.
use dbus to hit the play button in vlc
/*
g++ cppdbus.cpp -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include/ -lglib-2.0 -lgio-2.0 -lgobject-2.0
*/
#include <iostream>
#include <gio/gio.h>
int main()
{
GDBusConnection* conn = NULL;
GError* error = NULL;
conn = g_bus_get_sync( G_BUS_TYPE_SESSION, NULL, &error );
g_assert_no_error( error );
if (conn == NULL)
std::cout << "Error!" <<std::endl;
GError* error2 = NULL;
GDBusProxy* proxy = NULL;
proxy = g_dbus_proxy_new_sync( conn,
G_DBUS_PROXY_FLAGS_NONE,
NULL,
"org.mpris.MediaPlayer2.vlc",
"/org/mpris/MediaPlayer2",
"org.mpris.MediaPlayer2.Player",
NULL,
&error2 );
g_assert_no_error( error2 );
if( proxy == NULL )
std::cout << "Error!!" << std::endl;
g_dbus_proxy_call( proxy,
"Play", // I put anything here, compiler doesnt complain, program doesn't crash.
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL,
NULL );
}
@melvyniandrag
Copy link
Author

I didn't free anything or clean the code up or even make it do anything particularly interesting. Just spent a while reading about and playing with the gnome dbus bindings and finally have a snippet that actually does something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment