From 3e652b17cd0304633e04d71d2fe70492c3fbb00a Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Mon, 23 Oct 2017 18:34:56 -0700 Subject: binding: mediaplayer: add looping of playlist Allow playlist to be looped when it reachs the end of it. Bug-AGL: SPEC-931 Change-Id: I482c51d12234a5e70f76fbb981249a643b6b78fc Signed-off-by: Matt Ranostay --- binding/afm-common.c | 1 + binding/afm-common.h | 1 + binding/afm-mediaplayer-binding.c | 12 +++++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/binding/afm-common.c b/binding/afm-common.c index 3f0f38e..0f27d57 100644 --- a/binding/afm-common.c +++ b/binding/afm-common.c @@ -29,6 +29,7 @@ const char *control_commands[] = { "rewind", "pick-track", "volume", + "loop", }; int get_command_index(const char *name) diff --git a/binding/afm-common.h b/binding/afm-common.h index 8a418a1..5b36404 100644 --- a/binding/afm-common.h +++ b/binding/afm-common.h @@ -47,6 +47,7 @@ enum { REWIND_CMD, PICKTRACK_CMD, VOLUME_CMD, + LOOP_CMD, NUM_CMDS }; diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index 6c3c3b3..9e77dc1 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -42,6 +42,7 @@ static GList *current_track = NULL; typedef struct _CustomData { GstElement *playbin; gboolean playing; + gboolean loop; guint volume; gint64 position; gint64 duration; @@ -295,6 +296,7 @@ static int seek_track(int cmd) * * pick-track - select track via index number * volume - set volume between 0 - 100% + * loop - set looping of playlist (true or false) */ static void controls(struct afb_req request) @@ -379,6 +381,11 @@ static void controls(struct afb_req request) break; } + case LOOP_CMD: { + const char *state = afb_req_value(request, "state"); + data.loop = !strcasecmp(state, "true") ? TRUE : FALSE; + break; + } default: afb_req_fail(request, "failed", "unknown command"); pthread_mutex_unlock(&mutex); @@ -527,9 +534,12 @@ static gboolean handle_message(GstBus *bus, GstMessage *msg, CustomData *data) data->duration = GST_CLOCK_TIME_NONE; ret = seek_track(NEXT_CMD); + if (ret < 0) { - data->playing = FALSE; + if (!data->loop) + data->playing = FALSE; current_track = playlist; + set_media_uri(current_track->data); } else if (data->playing) { gst_element_set_state(data->playbin, GST_STATE_PLAYING); } -- cgit 1.2.3-korg