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 gchar dur_str[32], pos_str[32];
39 if (gst_element_query_position (element, GST_FORMAT_TIME, &position) &&
41 g_snprintf (pos_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (position));
43 g_snprintf (pos_str, 32, "-:--:--.---------");
46 if (gst_element_query_duration (element, GST_FORMAT_TIME, &duration) &&
48 g_snprintf (dur_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (duration));
50 g_snprintf (dur_str, 32, "-:--:--.---------");
53 g_print ("%s / %s\n", pos_str, dur_str);
59 warning_cb (GstBus * bus, GstMessage * msg, gpointer foo)
64 gst_message_parse_warning (msg, &err, &dbg);
66 g_printerr ("WARNING: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
73 error_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
78 gst_message_parse_error (msg, &err, &dbg);
80 g_printerr ("ERROR: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
82 g_main_loop_quit (main_loop);
89 eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
92 g_main_loop_quit (main_loop);
96 new_clock_cb (GstBus * bus, GstMessage * msg, gpointer nothing)
100 gst_message_parse_new_clock (msg, &clock);
101 g_print ("NEW CLOCK: %s\n", GST_OBJECT_NAME (clock));
105 clock_lost_cb (GstBus * bus, GstMessage * msg, GstElement * playbin)
109 gst_message_parse_clock_lost (msg, &clock);
110 g_print ("CLOCK LOST: %s\n", GST_OBJECT_NAME (clock));
112 gst_element_set_state (playbin, GST_STATE_PAUSED);
113 gst_element_set_state (playbin, GST_STATE_PLAYING);
117 about_to_finish_cb (GstElement * element, gchar * uri[])
119 if (arg_count < max_count) {
120 g_object_set (G_OBJECT (element), "uri", uri[arg_count], NULL);
126 main (gint argc, gchar * argv[])
128 GstStateChangeReturn res;
133 gst_init (&argc, &argv);
135 loop = g_main_loop_new (NULL, TRUE);
138 g_print ("usage: %s <uri> [<uri> ... ]\n", argv[0]);
142 player = gst_element_factory_make ("playbin2", "player");
145 bus = gst_pipeline_get_bus (GST_PIPELINE (player));
146 gst_bus_add_signal_watch (bus);
148 g_signal_connect (bus, "message::eos", G_CALLBACK (eos_cb), loop);
149 g_signal_connect (bus, "message::error", G_CALLBACK (error_cb), loop);
150 g_signal_connect (bus, "message::warning", G_CALLBACK (warning_cb), NULL);
151 g_signal_connect (bus, "message::new-clock", G_CALLBACK (new_clock_cb), NULL);
152 g_signal_connect (bus, "message::clock-lost", G_CALLBACK (clock_lost_cb),
155 g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
159 g_signal_connect (player, "about-to-finish", G_CALLBACK (about_to_finish_cb),
162 res = gst_element_set_state (player, GST_STATE_PLAYING);
163 if (res == GST_STATE_CHANGE_FAILURE) {
164 g_print ("could not play\n");
168 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, player);
170 g_main_loop_run (loop);
173 gst_element_set_state (player, GST_STATE_NULL);
174 gst_object_unref (player);
175 gst_object_unref (bus);