1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#ifndef _DBUS_PLAYER_H
#define _DBUS_PLAYER_H
#include <string.h>
#include <glib.h>
#include <gdk/gdk.h>
#include <gio/gio.h>
// Uncomment this to show debug messages from dbus-mpris2 and dbus-player modules.
//#define DEBUG_PLAYER
#if defined(DEBUG_PLAYER) || defined(DEBUG_ALL)
#define LOG_PLAYER LOG_MSG
#else
#define LOG_PLAYER(x, ...)
#endif
#define DBUS_MPRIS_TIMEOUT 400 // Milliseconds
#define PLAYER_STATUS_CLOSED -1
#define PLAYER_STATUS_STOPPED 0
#define PLAYER_STATUS_PAUSED 1
#define PLAYER_STATUS_PLAYING 2
#define PLAYER_STATUS_NOTIFY_MSG 3 // Send notification message to the GUI
#define RECORDING_DELETE_FILE 4
#define MPRIS_STRLEN 512
// Function pointers
typedef void (*GetTrackInfo)(gpointer player_rec); // player_rec = (MediaPlayerRec*)
typedef void (*SignalFunction)(gpointer player_rec, gboolean connect); // player_rec = (MediaPlayerRec*)
typedef gboolean (*AppIsRunning)(gpointer player_rec); // player_rec = (MediaPlayerRec*)
typedef void (*StartPlayer)(gpointer player_rec); // player_rec = (MediaPlayerRec*)
typedef struct {
gchar track[MPRIS_STRLEN+1]; // Track name (or GUI message if status==PLAYER_STATUS_NOTIFY_MSG)
gchar artist[MPRIS_STRLEN+1]; // Artist
gchar album[MPRIS_STRLEN+1]; // Album
gint status; // One of the PLAYER_STATUS_* values
gint total_secs; // Total track length in seconds
gint current_secs; // Currently played length in seconds
guint flags; // Possible RECORDING_DELETE_FILE flag
} TrackInfo;
typedef struct {
gint type; // MEDIA_PLAYER or COMM_PROGRAM
GDBusProxy *proxy; // Proxy for the "org.mpris.MediaPlayer2.Player" interface
GDBusProxy *prop_proxy; // Proxy for the "org.freedesktop.DBus.Properties" interface
gchar *exec_name; // Executable name from .desktop file
gchar *app_name; // Name of the app, eg. "Amarok 2.3.3", "Banshee 2.1" or "Skype"
gchar *icon_name; // Icon name
gchar *service_name; // Eg. "name:org.mpris.MediaPlayer2.banshee" or "com.Skype.API"
TrackInfo track; // See TrackInfo
GetTrackInfo func_get_info; // Function to get track data; name/artist/album/music genre/time etc.
SignalFunction func_set_signals; // Function to connect/disconnect DBus signals
AppIsRunning func_check_is_running;// Function to check if the app is running
StartPlayer func_start_app; // Function to run/start the player
} MediaPlayerRec;
void dbus_player_init();
void dbus_player_exit();
// Function to be called when media players send a request or data via the DBus.
typedef void (*DBusDataCallbackFunc)(MediaPlayerRec *player);
void dbus_player_set_callback_func(DBusDataCallbackFunc data_callback_func);
GHashTable *dbus_player_get_list_ref();
GHashTable *dbus_player_get_player_list();
MediaPlayerRec *dbus_player_lookup_app_name(gchar *app_name);
MediaPlayerRec *dbus_player_lookup_service_name(gchar *service_name);
void dbus_player_delete_item(gpointer data);
void dbus_player_debug_print(MediaPlayerRec *p);
void dbus_player_player_changed(gchar *service_name);
// Called by media players when they have new data
void dbus_player_process_data(gpointer player);
void dbus_player_send_notification(MediaPlayerRec *player, gchar *msg);
#endif
|