Created
April 10, 2018 21:14
-
-
Save melvyniandrag/6b1f562e9bb24b360b13ff48defc2608 to your computer and use it in GitHub Desktop.
use dbus to hit the play button in vlc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.