~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/dbus-player.c

  • Committer: Osmo Antero
  • Date: 2012-04-18 19:22:01 UTC
  • Revision ID: osmoma@gmail.com-20120418192201-ejjs6ikv7o4aznbi
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
#include <string.h>
20
20
#include <glib.h>
21
 
#include <gtk/gtk.h>
22
21
#include <gdk/gdk.h>
23
 
#include <dbus/dbus.h>
24
 
#include <dbus/dbus-glib.h>
 
22
#include <gio/gio.h>
 
23
#include <unistd.h>
25
24
 
26
25
#include "log.h"
27
26
#include "utility.h"
30
29
 
31
30
#include "audio-sources.h"
32
31
 
33
 
// Module for MPRIS compliant (standards following) players.
34
 
#include "dbus-mpris.h"
 
32
// MPRIS2 compliant players.
 
33
#include "dbus-mpris2.h"
35
34
 
36
 
// Handcrafted DBus interfaces for various Media Players, Skype, etc.
37
 
#include "dbus-rhythmbox.h"
38
 
#include "dbus-banshee.h"
 
35
// Handcrafted DBus-interfaces for Skype.
39
36
#include "dbus-skype.h"
40
37
 
41
 
// Glib/DBus connection
42
 
static DBusGConnection *g_dbus_conn = NULL;
43
 
 
44
38
// List of players
45
39
static GHashTable *g_player_list = NULL;
46
40
 
50
44
static void dbus_player_disconnect_signals();
51
45
static void dbus_player_clear_list();
52
46
 
53
 
void dbus_player_detect_software();
54
 
 
55
 
static void add_rhythmbox_player();
56
 
static void add_banshee_player();
 
47
void add_player_manually(gchar *app_name, gchar *exec_name, gchar *service_name);
 
48
void add_skype();
57
49
 
58
50
void dbus_player_init() {
59
51
    LOG_DEBUG("Init dbus-player.c.\n");
60
52
 
61
53
    g_player_list = NULL;
62
 
    g_dbus_conn = NULL;
63
54
 
64
55
    skype_module_init();
65
56
 
66
 
    mpris_module_init();
 
57
    mpris2_module_init();
67
58
}
68
59
 
69
60
void dbus_player_exit() {
72
63
    // Disconnect DBus signals for all Media Players
73
64
    dbus_player_disconnect_signals();
74
65
 
75
 
    // Disconnect g_dbus_conn from the DBus
76
 
    dbus_player_disconnect_from_dbus();
77
 
 
78
66
    // Clear the player list
79
67
    dbus_player_clear_list();
80
68
 
81
 
    mpris_module_exit();
 
69
    mpris2_module_exit();
82
70
 
83
71
    skype_module_exit();
84
72
}
174
162
    }
175
163
    player->proxy = NULL;
176
164
 
 
165
    if (G_IS_OBJECT(player->prop_proxy)) {
 
166
        g_object_unref(player->prop_proxy);
 
167
    }
 
168
    player->prop_proxy = NULL;
 
169
 
177
170
    g_free(player->service_name);
 
171
    g_free(player->exec_name);
178
172
    g_free(player->app_name);
179
173
    g_free(player->icon_name);
180
174
    g_free(player);
181
175
}
182
176
 
183
 
DBusGConnection *dbus_player_connect_to_dbus() {
184
 
    // Connect to glib/DBus
185
 
    GError *error = NULL;
186
 
 
187
 
    if (!g_dbus_conn) {
188
 
        g_dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
189
 
 
190
 
        if (!g_dbus_conn) {
191
 
            LOG_ERROR("dbus_player_connect_to_dbus: Cannot connect to DBus: %s\n", error ? error->message : "");
192
 
 
193
 
            if (error)
194
 
                g_error_free(error);
195
 
 
196
 
            return NULL;
197
 
        }
198
 
    }
199
 
    return g_dbus_conn;
200
 
}
201
 
 
202
 
void dbus_player_disconnect_from_dbus() {
203
 
    // Disconnect from glib/DBus
204
 
    if (g_dbus_conn)
205
 
        dbus_g_connection_unref(g_dbus_conn);
206
 
 
207
 
    g_dbus_conn = NULL;
208
 
}
209
 
 
210
177
MediaPlayerRec *dbus_player_lookup_app_name(gchar *app_name) {
211
178
    // Lookup player by its application name (p->app_name).
212
179
    // Typical app_names are "Amarok 2.3.2", "RhythmBox 2.3" and "Skype 2.1.0".
227
194
 
228
195
MediaPlayerRec *dbus_player_lookup_service_name(gchar *service_name) {
229
196
    // Lookup player by its service name (p->service_name).
230
 
    // Typical service_names are "org.gnome.Rhythmbox" and "com.Skype.API"
 
197
    // "org.mpris.MediaPlayer2.Player.banshee" is a typical service_name.
231
198
    GHashTableIter iter;
232
199
    gpointer key, value;
233
200
 
247
214
    LOG_PLAYER("------------------------------\n");
248
215
 
249
216
    LOG_PLAYER("Player app name:%s\n", p->app_name);
 
217
    LOG_PLAYER("Player exec name:%s\n", p->exec_name);
250
218
    LOG_PLAYER("Service name:%s\n", p->service_name);
251
219
 
252
 
    LOG_PLAYER("Player is active: %s\n", p->active ? "TRUE" : "FALSE");
253
 
 
254
 
    LOG_PLAYER("Flags:%d\n", p->flags);
255
 
 
256
220
    TrackInfo *tr = &p->track;
257
221
 
258
222
    switch (tr->status) {
259
223
    case PLAYER_STATUS_CLOSED:
260
 
        LOG_PLAYER("Status:%d  PLAYER_STATUS_CLOSED\n", tr->status);
 
224
        LOG_PLAYER("Status:%d  PLAYER_STATUS_CLOSED (not running)\n", tr->status);
261
225
        break;
262
226
 
263
227
    case PLAYER_STATUS_STOPPED:
272
236
        LOG_PLAYER("Status:%d  PLAYER_STATUS_PLAYING\n", tr->status);
273
237
        break;
274
238
 
275
 
    case PLAYER_STATUS_TRACK_CHANGE:
276
 
        LOG_PLAYER("Status:%d  PLAYER_STATUS_TRACK_CHANGE\n", tr->status);
277
 
        break;
278
 
 
279
239
    case PLAYER_STATUS_NOTIFY_MSG:
 
240
        // Simply a msg to the GUI.
280
241
        LOG_PLAYER("Status:%d  PLAYER_STATUS_NOTIFY_MSG\n", tr->status);
281
242
        break;
282
243
 
292
253
        LOG_PLAYER("Total length in seconds:%d\n", tr->total_secs);
293
254
        LOG_PLAYER("Flags:%d\n", tr->flags);
294
255
    } else {
 
256
        // Simply a msg to the GUI.
295
257
        LOG_PLAYER("Message:%s\n", tr->track);
296
258
    }
297
259
 
302
264
    // Clear the old list
303
265
    dbus_player_clear_list();
304
266
 
305
 
    // Connect to glib/DBus
306
 
    if (!dbus_player_connect_to_dbus()) {
307
 
        LOG_ERROR("dbus_player_get_players: Error, cannot connect to DBus.\n");
308
 
        return NULL;
309
 
    }
310
 
 
311
267
    // Populate the list.
312
 
    // Detect players that follow the MPRIS* standarden, such as Amarok.
313
 
    // Add also non-standard media players like Banshee and RhythmBox.
314
 
    // Add also Skype if it's installed.
315
 
    dbus_player_detect_software();
316
 
 
317
 
    // Add Rhythmbox manually (if installed)
318
 
    add_rhythmbox_player(TRUE);
319
 
 
320
 
    // Add Banshee manually (if installed)
321
 
    add_banshee_player(TRUE);
322
 
 
323
 
    // Add Totem (if installed)
324
 
    add_totem_player(TRUE);
325
 
 
326
 
    // Add Skype (if installed)
327
 
    add_skype(TRUE);
 
268
    // Detect players that follow the org.mpris.MediaPlayer2.* standard.
 
269
    mpris2_detect_players();
 
270
 
 
271
    // Make sure the most popular players are in the list. 
 
272
 
 
273
    // Add Rhythmbox manually (check if installed)
 
274
    // TODO: Should we translate the app-names?
 
275
    add_player_manually("Rhythmbox", "rhythmbox", "org.mpris.MediaPlayer2.rhythmbox");
 
276
 
 
277
    // Add Banshee manually (check if installed)
 
278
    add_player_manually("Banshee", "banshee", "org.mpris.MediaPlayer2.banshee");
 
279
 
 
280
    // Add Skype manually (check if installed)
 
281
    add_skype();
328
282
 
329
283
    return g_player_list;
330
284
}
331
285
 
332
 
void add_skype(gboolean find) {
 
286
void add_player_manually(gchar *app_name, gchar *exec_name, gchar *service_name) {
 
287
    // Add player manually to the list. Check if it's installed.
 
288
 
 
289
    // Already in the list?
 
290
    if (dbus_player_lookup_service_name(service_name)) return;
 
291
 
 
292
    // Find executable /usr/bin/exec_name
 
293
    gchar *path = find_command_path(exec_name);
 
294
    if (!path) {
 
295
        // Not installed.
 
296
        return;
 
297
    }
 
298
    g_free(path);
 
299
 
 
300
    // New MediaPlayer record
 
301
    MediaPlayerRec *player = mpris2_player_new(service_name);
 
302
 
 
303
    // Set executable
 
304
    player->exec_name = g_strdup(exec_name);
 
305
 
 
306
    // Set application name. This is shown in the listbox
 
307
    player->app_name = g_strdup(app_name);
 
308
 
 
309
    // Function to connect/disconnect event signals for this player
 
310
    player->func_set_signals = mpris2_set_signals;
 
311
 
 
312
    // Function to get track-info (album, track/song name/title, genre, etc.)
 
313
    player->func_get_info = mpris2_get_metadata;
 
314
 
 
315
    // Function to start/run the media player
 
316
    player->func_start_app = mpris2_start_app;
 
317
 
 
318
    // Function to check if this player is running
 
319
    player->func_check_is_running = mpris2_service_is_running;
 
320
 
 
321
    // Function to check if this player is up & running
 
322
    player->active = mpris2_service_is_running_by_name(service_name);
 
323
 
 
324
    // Set icon name
 
325
    player->icon_name = g_strdup_printf("%s.png", exec_name);
 
326
 
 
327
    if (!dbus_player_lookup_app_name(player->app_name)) {
 
328
        // Add to list
 
329
        GHashTable *player_list = dbus_player_get_list_ref();
 
330
        g_hash_table_insert(player_list, g_strdup(player->service_name), player);
 
331
    } else {
 
332
        // Duplicate or bad record. Free it.
 
333
        dbus_player_delete_item(player);
 
334
    }
 
335
}
 
336
 
 
337
void add_skype() {
333
338
    // Add Skype
334
339
 
335
340
    gchar *service_name = "com.Skype.API";
337
342
    // Already in the list?
338
343
    if (dbus_player_lookup_service_name(service_name)) return;
339
344
 
340
 
    if (find) {
341
 
        // Find /usr/bin/skype
342
 
        gchar *path = find_command_path("skype");
343
 
        if (!path) {
344
 
            return;
345
 
        }
346
 
        g_free(path);
 
345
    // Find /usr/bin/skype
 
346
    gchar *path = find_command_path("skype");
 
347
    if (!path) {
 
348
        // Not installed.
 
349
        return;
347
350
    }
 
351
    g_free(path);
348
352
 
349
353
    // New MediaPlayer record (yep, we store Skype data in a MediaPlayer record)
350
 
    MediaPlayerRec *player = mpris_player_new(service_name);
 
354
    MediaPlayerRec *player = mpris2_player_new(service_name);
351
355
 
352
356
    player->type = COMM_PROGRAM;
353
357
 
376
380
    }
377
381
}
378
382
 
379
 
void add_rhythmbox_player(gboolean find) {
380
 
    // Add RhythmBox
381
 
 
382
 
    gchar *service_name = "org.gnome.Rhythmbox";
383
 
 
384
 
    // Already in the list?
385
 
    if (dbus_player_lookup_service_name(service_name)) return;
386
 
 
387
 
    if (find) {
388
 
        // Find /usr/bin/rhythmbox
389
 
        gchar *path = find_command_path("rhythmbox");
390
 
        if (!path) {
391
 
            return;
392
 
        }
393
 
        g_free(path);
394
 
    }
395
 
 
396
 
    // New MediaPlayer record
397
 
    MediaPlayerRec *player = mpris_player_new(service_name);
398
 
 
399
 
    // Set real application name (player->app_name)
400
 
    // Rhythmbox does not understand the "Identity" message
401
 
 
402
 
    // Set real application name
403
 
    rhythmbox_get_app_name(player);
404
 
 
405
 
    // Function to connect/disconnect event signals for this player
406
 
    player->func_set_signals = rhythmbox_set_signals;
407
 
 
408
 
    // Function to get track-info (album, track/song name/title, genre, etc.)
409
 
    player->func_get_info = rhythmbox_get_info;
410
 
 
411
 
    // Function to start/run the media player
412
 
    player->func_start_app = rhythmbox_start_app;
413
 
 
414
 
    // Function to check if this player is up & running
415
 
    player->active = mpris_service_is_running_by_name(service_name);
416
 
 
417
 
    // Set icon
418
 
    player->icon_name = g_strdup("rhythmbox.png");
419
 
 
420
 
    if (!dbus_player_lookup_app_name(player->app_name)) {
421
 
        // Add to list
422
 
        GHashTable *player_list = dbus_player_get_list_ref();
423
 
        g_hash_table_insert(player_list, g_strdup(player->service_name), player);
424
 
    } else {
425
 
        // Duplicate or bad record. Free it.
426
 
        dbus_player_delete_item(player);
427
 
    }
428
 
}
429
 
 
430
 
static void add_banshee_player(gboolean find) {
431
 
    // Add Banshee
432
 
 
433
 
    gchar *service_name = "org.bansheeproject.Banshee";
434
 
 
435
 
    // Already in the list?
436
 
    if (dbus_player_lookup_service_name(service_name)) return;
437
 
 
438
 
    if (find) {
439
 
        // Find /usr/bin/banshee
440
 
        gchar *path = find_command_path("banshee");
441
 
        if (!path) {
442
 
            return;
443
 
        }
444
 
        g_free(path);
445
 
    }
446
 
 
447
 
    // New MediaPlayer record
448
 
    MediaPlayerRec *player = mpris_player_new(service_name);
449
 
 
450
 
    // Set real application name (player->app_name)
451
 
    // Banshee does not understand the "Identity" message
452
 
    banshee_get_app_name(player);
453
 
 
454
 
    // Function that can connect/disconnect event signals
455
 
    player->func_set_signals = banshee_set_signals;
456
 
 
457
 
    // Function to get track-info (album, track/song name/title, genre, etc.)
458
 
    player->func_get_info = banshee_get_info;
459
 
 
460
 
    // Function to start/run the media player
461
 
    player->func_start_app = banshee_start_app;
462
 
 
463
 
    // Function to check if this player is up & running
464
 
    player->active = mpris_service_is_running_by_name(service_name);
465
 
 
466
 
    // Set icon
467
 
    player->icon_name = g_strdup("banshee.png");
468
 
 
469
 
    if (!dbus_player_lookup_app_name(player->app_name)) {
470
 
        // Add to list
471
 
        GHashTable *player_list = dbus_player_get_list_ref();
472
 
        g_hash_table_insert(player_list, g_strdup(player->service_name), player);
473
 
 
474
 
    } else {
475
 
        // Duplicate or bad record. Free it.
476
 
        dbus_player_delete_item(player);
477
 
    }
478
 
}
479
 
 
480
 
void add_totem_player(gboolean find) {
481
 
    // Add Totem
482
 
 
483
 
    // ******************************
484
 
    // Totem player removed because it does now follow the MPRIS standard well.
485
 
    // ******************************
486
 
    return;
487
 
 
488
 
 
489
 
    gchar *service_name = "org.mpris.Totem";
490
 
 
491
 
    // Already in the list?
492
 
    if (dbus_player_lookup_service_name(service_name)) return;
493
 
 
494
 
    if (find) {
495
 
        // Find /usr/bin/totem
496
 
        gchar *path = find_command_path("totem");
497
 
        if (!path) {
498
 
            return;
499
 
        }
500
 
        g_free(path);
501
 
    }
502
 
 
503
 
    // New MediaPlayer record
504
 
    MediaPlayerRec *player = mpris_player_new(service_name);
505
 
 
506
 
    // Set real application name
507
 
    mpris_get_app_name(player);
508
 
 
509
 
    // Totem may not understand the "Identity" message!
510
 
    if (!player->app_name) {
511
 
        // Name of the Totem Media Player.
512
 
        player->app_name = g_strdup(_("Totem Media Player"));
513
 
    }
514
 
 
515
 
    // Function to connect/disconnect event signals
516
 
    player->func_set_signals = mpris_set_signals;
517
 
 
518
 
    // Function to get track-info (album, track/song name/title, genre, etc.)
519
 
    player->func_get_info = mpris_get_info;
520
 
 
521
 
    // Function to start/run the media player
522
 
    player->func_start_app = mpris_start_app;
523
 
 
524
 
    // Function to check if this player is up & running
525
 
    player->active = mpris_service_is_running_by_name(service_name);
526
 
 
527
 
    // Set icon
528
 
    player->icon_name = g_strdup("totem.png");
529
 
 
530
 
    if (!dbus_player_lookup_app_name(player->app_name)) {
531
 
        // Add to list
532
 
        GHashTable *player_list = dbus_player_get_list_ref();
533
 
        g_hash_table_insert(player_list, g_strdup(player->service_name), player);
534
 
 
535
 
    } else {
536
 
        // Duplicate or bad record. Free it.
537
 
        dbus_player_delete_item(player);
538
 
    }
539
 
}
540
 
 
541
383
void dbus_player_send_notification(MediaPlayerRec *player, gchar *msg) {
 
384
    // Send notification msg to the recorder/GUI.
542
385
    MediaPlayerRec *p = NULL;
543
386
    if (player) {
544
387
        p = player;
545
388
    } else {
546
 
        // Create a "dummy" MediaPlayerRec
547
 
        p = mpris_player_new(NULL);
 
389
        // Create a dummy MediaPlayerRec
 
390
        p = mpris2_player_new(NULL);
548
391
    }
549
392
 
550
 
    // Set active so the message goes through
551
 
    p->active = TRUE;
552
 
 
553
393
    // Send msg in the track field
554
394
    TrackInfo *tr = &p->track;
555
395
 
557
397
 
558
398
    tr->status = PLAYER_STATUS_NOTIFY_MSG;
559
399
 
560
 
    // Sends the message via dbus-player.c (as all DBus modules should do!)
 
400
    // Sends the message via dbus-player.c
561
401
    dbus_player_process_data(p);
562
402
 
563
 
    // Delete the tmp player
 
403
    // Delete the dummy thing
564
404
    if (!player) {
565
405
        dbus_player_delete_item(p);
566
406
    }
567
407
}
568
408
 
569
 
void dbus_player_detect_software() {
570
 
    // Get the list of DBus services (software that i sregistered on the DBus).
571
 
    // Add all MPRIS (org.mpris.*) compliant programs to player list.
572
 
 
573
 
#define DBUS_MPRIS_NAMESPACE "org.mpris."
574
 
 
575
 
    // Connect to glib/DBus
576
 
    DBusGConnection *dbus_conn = dbus_player_connect_to_dbus();
577
 
    if (!dbus_conn) return;
578
 
 
579
 
    // Get player list
580
 
    GHashTable *player_list = dbus_player_get_list_ref();
581
 
 
582
 
    // Get service names from the DBus
583
 
    char **name_list = NULL;
584
 
 
585
 
    // Reset error structure
586
 
    GError *error = NULL;
587
 
 
588
 
    // These values come from:
589
 
    // http://dbus.freedesktop.org/doc/api/html/group__DBusShared.html
590
 
    //
591
 
    // DBUS_SERVICE_DBUS   "org.freedesktop.DBus"
592
 
    // DBUS_PATH_DBUS      "/org/freedesktop/DBus"
593
 
    // DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
594
 
    DBusGProxy *proxy = dbus_g_proxy_new_for_name(dbus_conn,
595
 
                        DBUS_SERVICE_DBUS,
596
 
                        DBUS_PATH_DBUS,
597
 
                        DBUS_INTERFACE_DBUS);
598
 
 
599
 
    // Call ListNames method, wait for reply
600
 
    if (!dbus_g_proxy_call(proxy, "ListNames", &error, G_TYPE_INVALID, G_TYPE_STRV, &name_list, G_TYPE_INVALID)) {
601
 
        if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION)
602
 
            LOG_ERROR("dbus_player_detect_software: Caught remote method exception %s: %s", dbus_g_error_get_name(error), error->message);
603
 
        else
604
 
            LOG_ERROR("dbus_player_detect_software: %s\n", error->message);
605
 
 
606
 
        g_error_free(error);
607
 
        return;
608
 
    }
609
 
 
610
 
    // Loop through gchar *name_list[]
611
 
    gchar **cptr;
612
 
    for (cptr = name_list; *cptr; cptr++) {
613
 
        // Drop names that start with ":"
614
 
        gchar *service_name = *cptr;
615
 
 
616
 
        if (service_name && service_name[0] == ':')  {
617
 
            continue;
618
 
        }
619
 
 
620
 
        // MediaPlayer record
621
 
        MediaPlayerRec *player = NULL;
622
 
 
623
 
 
624
 
        // Uncomment this to see all found service names
625
 
        // LOG_PLAYER("DBus service_name:%s\n", service_name);
626
 
 
627
 
        // Non-standard (non-MPRIS) media player
628
 
        if (!strncmp(service_name, "org.gnome.Rhythmbox", strlen("org.gnome.Rhythmbox"))) {
629
 
 
630
 
            add_rhythmbox_player(FALSE);
631
 
 
632
 
        }
633
 
 
634
 
        // RhythmBox is MPRIS2 compatible player
635
 
        else if (!strncmp(service_name, "org.mpris.MediaPlayer2.rhythmbox", strlen("org.mpris.MediaPlayer2.rhythmbox"))) {
636
 
 
637
 
            // TODO: Add support for org.mpris.MediaPlayer2.rhythmbox
638
 
 
639
 
        }
640
 
 
641
 
        // Non-standard (non-MPRIS) media player
642
 
        else if (!strncmp(service_name, "org.bansheeproject.Banshee", strlen("org.bansheeproject.Banshee"))) {
643
 
 
644
 
            add_banshee_player(FALSE);
645
 
 
646
 
        }
647
 
 
648
 
        // Somehow non-standard (non-MPRIS) media player
649
 
        // else if (!strncmp(service_name, "org.gnome.Totem", strlen("org.gnome.Totem"))) {
650
 
        else if (!strncmp(service_name, "org.mpris.Totem", strlen("org.mpris.Totem"))) {
651
 
 
652
 
            add_totem_player(FALSE);
653
 
 
654
 
        }
655
 
 
656
 
        // Skype
657
 
        else if (!g_strcmp0(service_name, "com.Skype.API")) {
658
 
 
659
 
            add_skype(FALSE);
660
 
        }
661
 
 
662
 
        // Add all standard following media players (org.mpris.*).
663
 
        // Eg. The Amarok 2.x player implements the MPRIS DBus API well.
664
 
        else if (!strncmp(DBUS_MPRIS_NAMESPACE, service_name, strlen(DBUS_MPRIS_NAMESPACE))) {
665
 
 
666
 
            // New MediaPlayer record
667
 
            player = mpris_player_new(service_name);
668
 
 
669
 
            // Set real application name (player->app_name)
670
 
            mpris_get_app_name(player);
671
 
 
672
 
            // TODO: Check this. Remove hard-coding if possible.
673
 
            // Set icon.
674
 
            if (g_strrstr(player->service_name, "amarok") || g_strrstr(player->service_name, "Amarok")) {
675
 
                player->icon_name = g_strdup("amarok.png");
676
 
            } else {
677
 
                player->icon_name = g_strdup("sound.png");
678
 
            }
679
 
 
680
 
            // Function to connect/disconnect event signals for this players
681
 
            player->func_set_signals = mpris_set_signals;
682
 
 
683
 
            // Function to check if this player is running
684
 
            player->func_check_is_running = mpris_service_is_running;
685
 
 
686
 
            // Function to get track-info (album, track/song name/title, genre, etc.)
687
 
            player->func_get_info = mpris_get_info;
688
 
 
689
 
            // Function to start/run the media player
690
 
            player->func_start_app = mpris_start_app;
691
 
        }
692
 
 
693
 
        // Has a player record?
694
 
        if (player && player->app_name) {
695
 
 
696
 
            // Is this player running/is active?
697
 
            player->active = mpris_service_is_running_by_name(player->service_name);
698
 
 
699
 
            // Add player to the g_player_list.
700
 
 
701
 
            // Some players send double set of information to the DBus.
702
 
            // Eg. "Amarok 2.3.2" identifies itself as service_name 'org.mpris.amarok' and 'org.mpris.MediaPlayer2.amarok'.
703
 
 
704
 
            // Lookup the record by its app_name (like: "Amarok 2.3.2")
705
 
            if (!dbus_player_lookup_app_name(player->app_name)) {
706
 
                // Add it to the list
707
 
                g_hash_table_insert(player_list, g_strdup(player->service_name), player);
708
 
            } else {
709
 
                // Duplicate or bad record. Free it.
710
 
                dbus_player_delete_item(player);
711
 
            }
712
 
        }
713
 
    }
714
 
 
715
 
    // Free the name_list
716
 
    g_strfreev(name_list);
717
 
 
718
 
    // Unref the proxy
719
 
    g_object_unref(proxy);
720
 
 
721
 
}
722
 
 
723
409