tests: use elapsed label of volume example

This commit is contained in:
Luis de Bethencourt 2015-04-01 15:58:28 +01:00
parent b2db18cda2
commit bd2a86e353

View file

@ -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);