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