4 bus_call (GstBus * bus, GstMessage * msg, gpointer data)
6 GMainLoop *loop = (GMainLoop *) data;
8 switch (GST_MESSAGE_TYPE (msg)) {
10 g_print ("End-of-stream\n");
11 g_main_loop_quit (loop);
14 case GST_MESSAGE_ERROR:{
18 gst_message_parse_error (msg, &err, &debug);
21 g_print ("Error: %s\n", err->message);
24 g_main_loop_quit (loop);
35 main (gint argc, gchar * argv[])
42 gst_init (&argc, &argv);
45 g_print ("usage: %s <media file or uri>\n", argv[0]);
49 playbin = gst_element_factory_make ("playbin2", NULL);
51 g_print ("'playbin2' gstreamer plugin missing\n");
55 /* take the commandline argument and ensure that it is a uri */
56 if (gst_uri_is_valid (argv[1]))
57 uri = g_strdup (argv[1]);
59 uri = gst_filename_to_uri (argv[1], NULL);
60 g_object_set (playbin, "uri", uri, NULL);
63 /* create and event loop and feed gstreamer bus mesages to it */
64 loop = g_main_loop_new (NULL, FALSE);
66 bus = gst_element_get_bus (playbin);
67 gst_bus_add_watch (bus, bus_call, loop);
70 /* start play back and listed to events */
71 gst_element_set_state (playbin, GST_STATE_PLAYING);
72 g_main_loop_run (loop);
75 gst_element_set_state (playbin, GST_STATE_NULL);
76 g_object_unref (playbin);
77 g_main_loop_unref (loop);