1 #include <gst/gst.h>
2 #include <glib.h>
3 
4 
5 static gboolean
my_bus_callback(GstBus * bus,GstMessage * msg,gpointer data)6 my_bus_callback (GstBus     *bus,
7           GstMessage *msg,
8           gpointer    data)
9 {
10   GMainLoop *loop = (GMainLoop *) data;
11 
12   switch (GST_MESSAGE_TYPE (msg)) {
13 
14     case GST_MESSAGE_EOS:
15       g_print ("End of stream\n");
16       g_main_loop_quit (loop);
17       break;
18 
19     case GST_MESSAGE_ERROR: {
20       gchar  *debug;
21       GError *error;
22 
23       gst_message_parse_error (msg, &error, &debug);
24       g_free (debug);
25 
26       g_printerr ("Error: %s\n", error->message);
27       g_error_free (error);
28 
29       g_main_loop_quit (loop);
30       break;
31     }
32     default:
33       break;
34   }
35 
36   return TRUE;
37 }
38 
39 gint
main(gint argc,gchar * argv[])40 main (gint   argc,
41       gchar *argv[])
42 {
43   GMainLoop *loop;
44   GstElement *play;
45   GstBus *bus;
46 
47   /* init GStreamer */
48   gst_init (&argc, &argv);
49   loop = g_main_loop_new (NULL, FALSE);
50 
51   /* make sure we have a URI */
52   if (argc != 2) {
53     g_print ("Usage: %s <URI>\n", argv[0]);
54     return -1;
55   }
56 
57   /* set up */
58   play = gst_element_factory_make ("playbin", "play");
59   g_object_set (G_OBJECT (play), "uri", argv[1], NULL);
60 
61   bus = gst_pipeline_get_bus (GST_PIPELINE (play));
62   gst_bus_add_watch (bus, my_bus_callback, loop);
63   gst_object_unref (bus);
64 
65   gst_element_set_state (play, GST_STATE_PLAYING);
66 
67   /* now run */
68   g_main_loop_run (loop);
69 
70   /* also clean up */
71   gst_element_set_state (play, GST_STATE_NULL);
72   gst_object_unref (GST_OBJECT (play));
73 
74   return 0;
75 }
76