From 9d5f34e17c41332cddab11b71e15f28393f593c1 Mon Sep 17 00:00:00 2001 From: Matt Ranostay Date: Thu, 19 Oct 2017 21:14:33 -0700 Subject: binding: mediaplayer: previous command on first track rewinds to beginning If on first track on playlist and get previous track commands just rewind to beginning of that track. Bug-AGL: SPEC-931 Change-Id: Ie3decb70bd0826ad5199bdc9641befcc52cfd40a Signed-off-by: Matt Ranostay --- binding/afm-mediaplayer-binding.c | 55 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) (limited to 'binding/afm-mediaplayer-binding.c') diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c index b0876fa..3aab371 100644 --- a/binding/afm-mediaplayer-binding.c +++ b/binding/afm-mediaplayer-binding.c @@ -228,31 +228,6 @@ static void audio_playlist(struct afb_req request) pthread_mutex_unlock(&mutex); } -static int seek_track(int cmd) -{ - GList *item = NULL; - int ret; - - if (current_track == NULL) - return -EINVAL; - - item = (cmd == NEXT_CMD) ? current_track->next : current_track->prev; - - if (item == NULL) - return -EINVAL; - - ret = set_media_uri(item->data); - if (ret < 0) - return -EINVAL; - - if (data.playing) - gst_element_set_state(data.playbin, GST_STATE_PLAYING); - - current_track = item; - - return 0; -} - static int seek_stream(const char *value, int cmd) { gint64 position, current = 0; @@ -278,6 +253,36 @@ static int seek_stream(const char *value, int cmd) position * GST_MSECOND); } +static int seek_track(int cmd) +{ + GList *item = NULL; + int ret; + + if (current_track == NULL) + return -EINVAL; + + item = (cmd == NEXT_CMD) ? current_track->next : current_track->prev; + + if (item == NULL) { + if (cmd == PREVIOUS_CMD) { + seek_stream("0", SEEK_CMD); + return 0; + } + return -EINVAL; + } + + ret = set_media_uri(item->data); + if (ret < 0) + return -EINVAL; + + if (data.playing) + gst_element_set_state(data.playbin, GST_STATE_PLAYING); + + current_track = item; + + return 0; +} + /* @value can be one of the following values: * play - go to playing transition * pause - go to pause transition -- cgit 1.2.3-korg