|
1 /* GStreamer |
|
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> |
|
3 * |
|
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. |
|
8 * |
|
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. |
|
13 * |
|
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. |
|
18 */ |
|
19 #include <gst/gst.h> |
|
20 |
|
21 #define UPDATE_INTERVAL 500 |
|
22 |
|
23 static gboolean |
|
24 update_scale (GstElement * element) |
|
25 { |
|
26 gint64 duration = -1; |
|
27 gint64 position = -1; |
|
28 GstFormat format = GST_FORMAT_TIME; |
|
29 gchar dur_str[32], pos_str[32]; |
|
30 |
|
31 if (gst_element_query_position (element, &format, &position) && |
|
32 position != -1) { |
|
33 g_snprintf (pos_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (position)); |
|
34 } else { |
|
35 g_snprintf (pos_str, 32, "-:--:--.---------"); |
|
36 } |
|
37 |
|
38 if (gst_element_query_duration (element, &format, &duration) && |
|
39 duration != -1) { |
|
40 g_snprintf (dur_str, 32, "%" GST_TIME_FORMAT, GST_TIME_ARGS (duration)); |
|
41 } else { |
|
42 g_snprintf (dur_str, 32, "-:--:--.---------"); |
|
43 } |
|
44 |
|
45 g_print ("%s / %s\n", pos_str, dur_str); |
|
46 |
|
47 return TRUE; |
|
48 } |
|
49 |
|
50 static void |
|
51 warning_cb (GstBus * bus, GstMessage * msg, gpointer foo) |
|
52 { |
|
53 GError *err = NULL; |
|
54 gchar *dbg = NULL; |
|
55 |
|
56 gst_message_parse_warning (msg, &err, &dbg); |
|
57 |
|
58 g_printerr ("WARNING: %s (%s)\n", err->message, (dbg) ? dbg : "no details"); |
|
59 |
|
60 g_error_free (err); |
|
61 g_free (dbg); |
|
62 } |
|
63 |
|
64 static void |
|
65 error_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop) |
|
66 { |
|
67 GError *err = NULL; |
|
68 gchar *dbg = NULL; |
|
69 |
|
70 gst_message_parse_error (msg, &err, &dbg); |
|
71 |
|
72 g_printerr ("ERROR: %s (%s)\n", err->message, (dbg) ? dbg : "no details"); |
|
73 |
|
74 g_main_loop_quit (main_loop); |
|
75 |
|
76 g_error_free (err); |
|
77 g_free (dbg); |
|
78 } |
|
79 |
|
80 static void |
|
81 eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop) |
|
82 { |
|
83 g_print ("EOS\n"); |
|
84 g_main_loop_quit (main_loop); |
|
85 } |
|
86 |
|
87 |
|
88 gint |
|
89 main (gint argc, gchar * argv[]) |
|
90 { |
|
91 GstStateChangeReturn res; |
|
92 GstElement *player; |
|
93 GMainLoop *loop; |
|
94 GstBus *bus; |
|
95 |
|
96 gst_init (&argc, &argv); |
|
97 |
|
98 loop = g_main_loop_new (NULL, TRUE); |
|
99 |
|
100 player = gst_element_factory_make ("playbin", "player"); |
|
101 g_assert (player); |
|
102 |
|
103 bus = gst_pipeline_get_bus (GST_PIPELINE (player)); |
|
104 gst_bus_add_signal_watch (bus); |
|
105 |
|
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); |
|
109 |
|
110 g_object_set (G_OBJECT (player), "uri", argv[1], NULL); |
|
111 |
|
112 res = gst_element_set_state (player, GST_STATE_PLAYING); |
|
113 if (res == GST_STATE_CHANGE_FAILURE) { |
|
114 g_print ("could not play\n"); |
|
115 return -1; |
|
116 } |
|
117 |
|
118 g_timeout_add (UPDATE_INTERVAL, (GSourceFunc) update_scale, player); |
|
119 |
|
120 g_main_loop_run (loop); |
|
121 |
|
122 /* tidy up */ |
|
123 gst_element_set_state (player, GST_STATE_NULL); |
|
124 gst_object_unref (player); |
|
125 gst_object_unref (bus); |
|
126 |
|
127 return 0; |
|
128 } |