5 event_loop (GstElement * pipe)
8 GstMessage *message = NULL;
10 bus = gst_element_get_bus (GST_ELEMENT (pipe));
13 message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
15 g_assert (message != NULL);
17 switch (message->type) {
19 gst_message_unref (message);
21 case GST_MESSAGE_WARNING:
22 case GST_MESSAGE_ERROR:{
26 gst_message_parse_error (message, &gerror, &debug);
27 gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
28 gst_message_unref (message);
29 g_error_free (gerror);
34 gst_message_unref (message);
41 main (int argc, char *argv[])
43 GstElement *bin, *filesrc, *decoder, *audiosink;
45 gst_init (&argc, &argv);
48 g_print ("usage: %s <mp3 file>\n", argv[0]);
52 /* create a new bin to hold the elements */
53 bin = gst_pipeline_new ("pipeline");
56 /* create a disk reader */
57 filesrc = gst_element_factory_make ("filesrc", "disk_source");
59 g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
61 /* now it's time to get the decoder */
62 decoder = gst_element_factory_make ("mad", "decode");
64 g_print ("could not find plugin \"mad\"");
67 /* and an audio sink */
68 audiosink = gst_element_factory_make ("alsasink", "play_audio");
71 /* add objects to the main pipeline */
72 gst_bin_add_many (GST_BIN (bin), filesrc, decoder, audiosink, NULL);
74 /* link the elements */
75 gst_element_link_many (filesrc, decoder, audiosink, NULL);
78 gst_element_set_state (bin, GST_STATE_PLAYING);
80 /* Run event loop listening for bus messages until EOS or ERROR */
84 gst_element_set_state (bin, GST_STATE_NULL);