Skip to content

Commit

Permalink
Merge pull request #79 from cnt0/master
Browse files Browse the repository at this point in the history
add Player.OpenUri command handler
  • Loading branch information
Tony Crisci authored Sep 26, 2018
2 parents d577e85 + 50d5061 commit a3694bf
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions playerctl/playerctl-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ static gboolean previous (PlayerctlPlayer *player, gchar **arguments, GError **e

#undef PLAYER_COMMAND_FUNC

static gboolean open (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
const gchar *uri = *arguments;
GError *tmp_error = NULL;
if (uri) {
playerctl_player_open(player, g_file_get_uri(g_file_new_for_commandline_arg(uri)), &tmp_error);
if (tmp_error != NULL) {
g_propagate_error(error, tmp_error);
return FALSE;
}
}
return TRUE;
}

static gboolean position (PlayerctlPlayer *player, gchar **arguments, GError **error)
{
const gchar *position = *arguments;
Expand Down Expand Up @@ -276,6 +290,7 @@ struct PlayerCommand {
const gchar *name;
gboolean (*func) (PlayerctlPlayer *player, gchar **arguments, GError **error);
} commands[] = {
{ "open", &open },
{ "play", &play },
{ "pause", &paus },
{ "play-pause", &play_pause },
Expand Down Expand Up @@ -316,6 +331,8 @@ static const GOptionEntry entries[] = {
static gboolean parse_setup_options (int argc, char *argv[], GError **error)
{
static const gchar *description = "Available Commands:"
"\n open [URI] Command for the player to open given URI."
"\n URI can be either file path or remote URL with mandatory scheme, like http://..."
"\n play Command the player to play"
"\n pause Command the player to pause"
"\n play-pause Command the player to toggle between play/pause"
Expand Down
30 changes: 30 additions & 0 deletions playerctl/playerctl-player.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,36 @@ PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self, GError **err
PLAYER_COMMAND_FUNC(play_pause);
}

/**
* playerctl_player_open:
* @self: a #PlayerctlPlayer
* @err (allow-none): the location of a GError or NULL
*
* Command the player to open given URI
*
* Returns: (transfer none): the #PlayerctlPlayer for chaining
*/
PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri, GError **err)
{
GError *tmp_error = NULL;

g_return_val_if_fail(self != NULL, NULL);
g_return_val_if_fail(err == NULL || *err == NULL, NULL);

if (self->priv->init_error != NULL) {
g_propagate_error(err, g_error_copy(self->priv->init_error));
return self;
}
org_mpris_media_player2_player_call_open_uri_sync(self->priv->proxy, uri, NULL, &tmp_error);

if (tmp_error != NULL) {
g_propagate_error(err, tmp_error);
return self;
}

return self;
}

/**
* playerctl_player_play:
* @self: a #PlayerctlPlayer
Expand Down
2 changes: 2 additions & 0 deletions playerctl/playerctl-player.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ PlayerctlPlayer *playerctl_player_new (const gchar *name, GError **err);

PlayerctlPlayer *playerctl_player_on(PlayerctlPlayer *self, const gchar *event, GClosure *callback, GError **err);

PlayerctlPlayer *playerctl_player_open(PlayerctlPlayer *self, gchar *uri, GError **err);

PlayerctlPlayer *playerctl_player_play_pause(PlayerctlPlayer *self, GError **err);

PlayerctlPlayer *playerctl_player_play(PlayerctlPlayer *self, GError **err);
Expand Down

0 comments on commit a3694bf

Please sign in to comment.