From bd2a86e3531bb9000f8a093dfd8374dd3d2c18c9 Mon Sep 17 00:00:00 2001 From: Luis de Bethencourt Date: Wed, 1 Apr 2015 15:58:28 +0100 Subject: [PATCH] tests: use elapsed label of volume example --- tests/examples/audio/volume.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/tests/examples/audio/volume.c b/tests/examples/audio/volume.c index 04ca93bb38..398bc4f7b9 100644 --- a/tests/examples/audio/volume.c +++ b/tests/examples/audio/volume.c @@ -64,8 +64,8 @@ setup_gui (GstElement * volume) /* elapsed widget */ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); - label = gtk_label_new ("Elapsed"); - elapsed = gtk_label_new ("0.000"); + label = gtk_label_new ("Elapsed: "); + elapsed = gtk_label_new ("0.0"); gtk_container_add (GTK_CONTAINER (hbox), label); gtk_container_add (GTK_CONTAINER (hbox), elapsed); gtk_container_add (GTK_CONTAINER (vbox), hbox); @@ -86,6 +86,24 @@ setup_gui (GstElement * volume) gtk_widget_show_all (GTK_WIDGET (window)); } +static gboolean +progress_update (gpointer data) +{ + GstElement *pipeline = (GstElement *) data; + gint64 position; + gchar *position_str; + + if (gst_element_query_position (pipeline, GST_FORMAT_TIME, &position)) + position_str = g_strdup_printf ("%.1f", (gfloat) position / GST_SECOND); + else + position_str = g_strdup_printf ("n/a"); + gtk_label_set_text (GTK_LABEL (elapsed), position_str); + + g_free (position_str); + + return TRUE; +} + static void message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) { @@ -165,6 +183,7 @@ main (int argc, char *argv[]) /* go to main loop */ gst_element_set_state (pipeline, GST_STATE_PLAYING); + g_timeout_add (100, progress_update, pipeline); gtk_main (); gst_element_set_state (pipeline, GST_STATE_NULL); gst_object_unref (pipeline);