2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 #define UPDATE_INTERVAL 500
24 update_scale (GstElement * element)
28 GstFormat format = GST_FORMAT_TIME;
29 gchar dur_str[32], pos_str[32];
31 if (gst_element_query_position (element, &format, &position) &&
33 g_snprintf (pos_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (position));
35 g_snprintf (pos_str, 32, "-:--:--.---------");
38 if (gst_element_query_duration (element, &format, &duration) &&
40 g_snprintf (dur_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (duration));
42 g_snprintf (dur_str, 32, "-:--:--.---------");
45 g_print ("%s / %s\n", pos_str, dur_str);
51 warning_cb (GstBus * bus, GstMessage * msg, gpointer foo)
56 gst_message_parse_warning (msg, &err, &dbg);
58 g_printerr ("WARNING: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
65 error_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
70 gst_message_parse_error (msg, &err, &dbg);
72 g_printerr ("ERROR: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
74 g_main_loop_quit (main_loop);
81 eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
84 g_main_loop_quit (main_loop);
89 main (gint argc, gchar * argv[])
91 GstStateChangeReturn res;
96 gst_init (&argc, &argv);
98 loop = g_main_loop_new (NULL, TRUE);
100 player = gst_element_factory_make ("playbin", "player");
103 bus = gst_pipeline_get_bus (GST_PIPELINE (player));
104 gst_bus_add_signal_watch (bus);
106 g_signal_connect (bus, "message::eos", G_CALLBACK (eos_cb), loop);
107 g_signal_connect (bus, "message::error", G_CALLBACK (error_cb), loop);
108 g_signal_connect (bus, "message::warning", G_CALLBACK (warning_cb), NULL);
110 g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
112 res = gst_element_set_state (player, GST_STATE_PLAYING);
113 if (res == GST_STATE_CHANGE_FAILURE) {
114 g_print ("could not play\n");
118 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, player);
120 g_main_loop_run (loop);
123 gst_element_set_state (player, GST_STATE_NULL);
124 gst_object_unref (player);
125 gst_object_unref (bus);