Merge pull request #79 from cnt0/master

add Player.OpenUri command handler
This commit is contained in:
Tony Crisci
2018-09-26 09:56:54 -04:00
committed by GitHub
3 changed files with 49 additions and 0 deletions

View File

@@ -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;
@@ -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 },
@@ -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"

View File

@@ -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

View File

@@ -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);