summaryrefslogtreecommitdiffstats
path: root/binding/afm-mediaplayer-binding.c
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2017-11-06 18:29:54 -0800
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-11-06 21:58:49 -0800
commitadf97a14d996790e22893579ef2004b420283df9 (patch)
tree9a9c457b8a26cef9f48d744b4bb1c9afab8f315f /binding/afm-mediaplayer-binding.c
parent9273ade2b8783ac39c9cd5dc96d7c45621519a8c (diff)
binding: mediaplayer: add support for initial metadata on startup
Use a fakesink to get initial album art metadata on startup of service Bug-AGL: SPEC-1052 Change-Id: If3563e65480ba1a159d60e04d8fe7e63d12301a4 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding/afm-mediaplayer-binding.c')
-rw-r--r--binding/afm-mediaplayer-binding.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/binding/afm-mediaplayer-binding.c b/binding/afm-mediaplayer-binding.c
index 4ba4e9e..ed532a8 100644
--- a/binding/afm-mediaplayer-binding.c
+++ b/binding/afm-mediaplayer-binding.c
@@ -40,7 +40,7 @@ static GList *playlist = NULL;
static GList *current_track = NULL;
typedef struct _CustomData {
- GstElement *playbin;
+ GstElement *playbin, *fake_sink, *alsa_sink;
gboolean playing;
gboolean loop;
gboolean one_time;
@@ -145,8 +145,13 @@ static int set_media_uri(struct playlist_item *item)
data.position = GST_CLOCK_TIME_NONE;
data.duration = GST_CLOCK_TIME_NONE;
- if (data.playing)
+ if (data.playing) {
+ g_object_set(data.playbin, "audio-sink", data.alsa_sink, NULL);
gst_element_set_state(data.playbin, GST_STATE_PLAYING);
+ } else {
+ g_object_set(data.playbin, "audio-sink", data.fake_sink, NULL);
+ gst_element_set_state(data.playbin, GST_STATE_PAUSED);
+ }
g_object_set(data.playbin, "volume", (double) data.volume / 100.0, NULL);
@@ -279,13 +284,11 @@ static int seek_track(int cmd)
return -EINVAL;
}
+ data.playing = TRUE;
ret = set_media_uri(item->data);
if (ret < 0)
return -EINVAL;
- data.playing = TRUE;
- gst_element_set_state(data.playbin, GST_STATE_PLAYING);
-
current_track = item;
return 0;
@@ -322,12 +325,22 @@ static void controls(struct afb_req request)
errno = 0;
switch (cmd) {
- case PLAY_CMD:
- jresp = json_object_new_object();
- gst_element_set_state(data.playbin, GST_STATE_PLAYING);
+ case PLAY_CMD: {
+ GstElement *obj = NULL;
data.playing = TRUE;
+ g_object_get(data.playbin, "audio-sink", &obj, NULL);
+
+ if (obj == data.fake_sink) {
+ set_media_uri(current_track->data);
+ } else {
+ g_object_set(data.playbin, "audio-sink", data.alsa_sink, NULL);
+ gst_element_set_state(data.playbin, GST_STATE_PLAYING);
+ }
+
+ jresp = json_object_new_object();
json_object_object_add(jresp, "playing", json_object_new_boolean(TRUE));
break;
+ }
case PAUSE_CMD:
jresp = json_object_new_object();
gst_element_set_state(data.playbin, GST_STATE_PAUSED);
@@ -636,6 +649,12 @@ static void *gstreamer_loop_thread(void *ptr)
exit(1);
}
+ data.fake_sink = gst_element_factory_make("fakesink", NULL);
+ data.alsa_sink = gst_element_factory_make("alsasink", NULL);
+
+ g_object_set(data.playbin, "audio-sink", data.fake_sink, NULL);
+ gst_element_set_state(data.playbin, GST_STATE_PAUSED);
+
bus = gst_element_get_bus(data.playbin);
gst_bus_add_watch(bus, (GstBusFunc) handle_message, &data);
g_timeout_add_seconds(1, (GSourceFunc) position_event, &data);