From 3bc044cba40fd9a432276d063e6f4c08ca9ebc3e Mon Sep 17 00:00:00 2001 From: Xavi Artigas Date: Thu, 13 Sep 2012 16:35:51 +0200 Subject: [PATCH] Add a SeekBar to show current position / duration --- .../tutorials/android-tutorial-1/jni/tutorial-1.c | 45 +++++++++++----------- .../android-tutorial-1/res/layout/main.xml | 12 +++++- .../gst_sdk_tutorials/tutorial_1/Tutorial1.java | 6 ++- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/gst-sdk/tutorials/android-tutorial-1/jni/tutorial-1.c b/gst-sdk/tutorials/android-tutorial-1/jni/tutorial-1.c index c35141c..c5d037d 100755 --- a/gst-sdk/tutorials/android-tutorial-1/jni/tutorial-1.c +++ b/gst-sdk/tutorials/android-tutorial-1/jni/tutorial-1.c @@ -96,6 +96,28 @@ static void set_current_position (gint64 position, gint64 duration, CustomData * } } +static gboolean refresh_ui (CustomData *data) { + GstFormat fmt = GST_FORMAT_TIME; + gint64 current = -1; + + /* We do not want to update anything unless we are in the PLAYING state */ + if (!data->playing) + return TRUE; + + /* If we didn't know it yet, query the stream duration */ + if (!GST_CLOCK_TIME_IS_VALID (data->duration)) { + if (!gst_element_query_duration (data->pipeline, &fmt, &data->duration)) { + GST_WARNING ("Could not query current duration"); + } + } + + if (gst_element_query_position (data->pipeline, &fmt, &data->position)) { + /* Java expects these values in milliseconds, and Gst provides nanoseconds */ + set_current_position (data->position/1000000, data->duration/1000000, data); + } + return TRUE; +} + static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) { GError *err; gchar *debug_info; @@ -112,6 +134,7 @@ static void error_cb (GstBus *bus, GstMessage *msg, CustomData *data) { static void eos_cb (GstBus *bus, GstMessage *msg, CustomData *data) { set_message (GST_MESSAGE_TYPE_NAME (msg), data); + refresh_ui (data); gst_element_set_state (data->pipeline, GST_STATE_NULL); } @@ -124,28 +147,6 @@ static void state_changed_cb (GstBus *bus, GstMessage *msg, CustomData *data) { } } -static gboolean refresh_ui (CustomData *data) { - GstFormat fmt = GST_FORMAT_TIME; - gint64 current = -1; - - /* We do not want to update anything unless we are in the PLAYING state */ - if (!data->playing) - return TRUE; - - /* If we didn't know it yet, query the stream duration */ - if (!GST_CLOCK_TIME_IS_VALID (data->duration)) { - if (!gst_element_query_duration (data->pipeline, &fmt, &data->duration)) { - GST_WARNING ("Could not query current duration"); - } - } - - if (gst_element_query_position (data->pipeline, &fmt, &data->position)) { - /* Java expects these values in milliseconds, and Gst provides nanoseconds */ - set_current_position (data->position/1000000, data->duration/1000000, data); - } - return TRUE; -} - static void *app_function (void *userdata) { JavaVMAttachArgs args; GstBus *bus; diff --git a/gst-sdk/tutorials/android-tutorial-1/res/layout/main.xml b/gst-sdk/tutorials/android-tutorial-1/res/layout/main.xml index edf04e3..4c3e100 100755 --- a/gst-sdk/tutorials/android-tutorial-1/res/layout/main.xml +++ b/gst-sdk/tutorials/android-tutorial-1/res/layout/main.xml @@ -34,7 +34,17 @@ android:id="@+id/textview_time" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_gravity="center_vertical" /> + android:layout_gravity="center_vertical" + android:layout_marginLeft="5dip" + android:layout_marginRight="5dip" /> + +