From: Mike Brady Date: Sun, 19 Nov 2017 21:40:09 +0000 (+0000) Subject: Handle play / pause / play-pause / stop but primitively X-Git-Tag: 3.2d13~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b98e2a085412ee0b69afe52f10172f5a6536ddca;p=thirdparty%2Fshairport-sync.git Handle play / pause / play-pause / stop but primitively --- diff --git a/.gitignore b/.gitignore index d59bf168..ffed6d6d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /shairport-sync /shairport-sync.exe /shairport-sync-dbus-test-client +/shairport-sync-mpris-test-client *.o /*~ @@ -31,6 +32,7 @@ shairport-sync.core /org.gnome.ShairportSync.service /dbus-interface.* /mpris-interface.* +/mpris-player-interface.* # Some eclipse project files .cproject diff --git a/mpris-service.c b/mpris-service.c index 6331a5c8..c96a7749 100644 --- a/mpris-service.c +++ b/mpris-service.c @@ -12,14 +12,13 @@ #include "dacp.h" #include "mpris-service.h" - -static gboolean on_handle_stop(MediaPlayer2Player *skeleton, GDBusMethodInvocation *invocation, - gpointer user_data) { - debug(1, "DBUS Command to Stop"); +int send_simple_dacp_command(const char* command) { + int reply = 0; if (playing_conn) { char server_reply[2000]; + debug(1,"Sending command \"%s\".",command); ssize_t reply_size = - dacp_send_client_command(playing_conn, "stop", server_reply, sizeof(server_reply)); + dacp_send_client_command(playing_conn, command, server_reply, sizeof(server_reply)); if (reply_size >= 0) { // not interested in the response. // if (strstr(server_reply, "HTTP/1.1 204") == server_reply) { @@ -43,14 +42,42 @@ static gboolean on_handle_stop(MediaPlayer2Player *skeleton, GDBusMethodInvocati } } else { debug(1, "Error at rtp_send_client_command"); + reply = -1; } } else { debug(1, "no thread playing -- RemoteCommand ignored."); + reply = -1; } + return reply; +} + +static gboolean on_handle_stop(MediaPlayer2Player *skeleton, GDBusMethodInvocation *invocation, + gpointer user_data) { + send_simple_dacp_command("stop"); media_player2_player_complete_stop(skeleton, invocation); return TRUE; } +static gboolean on_handle_pause(MediaPlayer2Player *skeleton, GDBusMethodInvocation *invocation, + gpointer user_data) { + send_simple_dacp_command("pause"); + media_player2_player_complete_pause(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_play_pause(MediaPlayer2Player *skeleton, GDBusMethodInvocation *invocation, + gpointer user_data) { + send_simple_dacp_command("playpause"); + media_player2_player_complete_play_pause(skeleton, invocation); + return TRUE; +} + +static gboolean on_handle_play(MediaPlayer2Player *skeleton, GDBusMethodInvocation *invocation, + gpointer user_data) { + send_simple_dacp_command("play"); + media_player2_player_complete_play(skeleton, invocation); + return TRUE; +} static void on_mpris_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data) { @@ -87,9 +114,9 @@ const char* empty_string_array[] = { media_player2_player_set_can_seek (mprisPlayerPlayerSkeleton, FALSE); media_player2_player_set_can_control (mprisPlayerPlayerSkeleton, TRUE); -// g_signal_connect(mprisPlayerPlayerSkeleton, "handle-play", G_CALLBACK(on_handle_play), NULL); -// g_signal_connect(mprisPlayerPlayerSkeleton, "handle-pause", G_CALLBACK(on_handle_pause), NULL); -// g_signal_connect(mprisPlayerPlayerSkeleton, "handle-play-pause", G_CALLBACK(on_handle_play_pause), NULL); + g_signal_connect(mprisPlayerPlayerSkeleton, "handle-play", G_CALLBACK(on_handle_play), NULL); + g_signal_connect(mprisPlayerPlayerSkeleton, "handle-pause", G_CALLBACK(on_handle_pause), NULL); + g_signal_connect(mprisPlayerPlayerSkeleton, "handle-play-pause", G_CALLBACK(on_handle_play_pause), NULL); g_signal_connect(mprisPlayerPlayerSkeleton, "handle-stop", G_CALLBACK(on_handle_stop), NULL); debug(1,"Shairport Sync D-BUS service started on interface \"%s\".",name);