2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
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.
23 #include <stdlib.h> /* exit() */
27 #define UPDATE_INTERVAL 500
33 update_scale (GstElement * element)
37 GstFormat format = GST_FORMAT_TIME;
38 gchar dur_str[32], pos_str[32];
40 if (gst_element_query_position (element, &format, &position) &&
42 g_snprintf (pos_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (position));
44 g_snprintf (pos_str, 32, "-:--:--.---------");
47 if (gst_element_query_duration (element, &format, &duration) &&
49 g_snprintf (dur_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (duration));
51 g_snprintf (dur_str, 32, "-:--:--.---------");
54 g_print ("%s / %s\n", pos_str, dur_str);
60 warning_cb (GstBus * bus, GstMessage * msg, gpointer foo)
65 gst_message_parse_warning (msg, &err, &dbg);
67 g_printerr ("WARNING: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
74 error_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
79 gst_message_parse_error (msg, &err, &dbg);
81 g_printerr ("ERROR: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
83 g_main_loop_quit (main_loop);
90 eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
93 g_main_loop_quit (main_loop);
97 new_clock_cb (GstBus * bus, GstMessage * msg, gpointer nothing)
101 gst_message_parse_new_clock (msg, &clock);
102 g_print ("NEW CLOCK: %s\n", GST_OBJECT_NAME (clock));
106 clock_lost_cb (GstBus * bus, GstMessage * msg, GstElement * playbin)
110 gst_message_parse_clock_lost (msg, &clock);
111 g_print ("CLOCK LOST: %s\n", GST_OBJECT_NAME (clock));
113 gst_element_set_state (playbin, GST_STATE_PAUSED);
114 gst_element_set_state (playbin, GST_STATE_PLAYING);
118 about_to_finish_cb (GstElement * element, gchar * uri[])
120 if (arg_count < max_count) {
121 g_object_set (G_OBJECT (element), "uri", uri[arg_count], NULL);
127 main (gint argc, gchar * argv[])
129 GstStateChangeReturn res;
134 gst_init (&argc, &argv);
136 loop = g_main_loop_new (NULL, TRUE);
139 g_print ("usage: %s <uri> [<uri> ... ]\n", argv[0]);
143 player = gst_element_factory_make ("playbin2", "player");
146 bus = gst_pipeline_get_bus (GST_PIPELINE (player));
147 gst_bus_add_signal_watch (bus);
149 g_signal_connect (bus, "message::eos", G_CALLBACK (eos_cb), loop);
150 g_signal_connect (bus, "message::error", G_CALLBACK (error_cb), loop);
151 g_signal_connect (bus, "message::warning", G_CALLBACK (warning_cb), NULL);
152 g_signal_connect (bus, "message::new-clock", G_CALLBACK (new_clock_cb), NULL);
153 g_signal_connect (bus, "message::clock-lost", G_CALLBACK (clock_lost_cb),
156 g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
160 g_signal_connect (player, "about-to-finish", G_CALLBACK (about_to_finish_cb),
163 res = gst_element_set_state (player, GST_STATE_PLAYING);
164 if (res == GST_STATE_CHANGE_FAILURE) {
165 g_print ("could not play\n");
169 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, player);
171 g_main_loop_run (loop);
174 gst_element_set_state (player, GST_STATE_NULL);
175 gst_object_unref (player);
176 gst_object_unref (bus);