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., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <stdlib.h> /* exit() */
24
25 #include <gst/gst.h>
26
27 static GMainLoop *loop;
28
29 static void
error_eos_cb(GstBus * bus,GstMessage * msg,GMainLoop * main_loop)30 error_eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
31 {
32 g_main_loop_quit (main_loop);
33 }
34
35 gint
main(gint argc,gchar * argv[])36 main (gint argc, gchar * argv[])
37 {
38 GstElement *player;
39 GstStateChangeReturn res;
40 GstBus *bus;
41
42 gst_init (&argc, &argv);
43
44 player = gst_element_factory_make ("playbin", "player");
45 g_assert (player);
46
47 if (argc < 2) {
48 g_print ("usage: %s <uri>\n", argv[0]);
49 exit (-1);
50 }
51
52 loop = g_main_loop_new (NULL, TRUE);
53 bus = gst_pipeline_get_bus (GST_PIPELINE (player));
54 gst_bus_add_signal_watch (bus);
55
56 g_signal_connect (bus, "message::eos", G_CALLBACK (error_eos_cb), loop);
57 g_signal_connect (bus, "message::error", G_CALLBACK (error_eos_cb), loop);
58
59 g_object_set (G_OBJECT (player), "uri", argv[1], NULL);
60
61 g_print ("play...\n");
62 res = gst_element_set_state (player, GST_STATE_PLAYING);
63 if (res == GST_STATE_CHANGE_FAILURE) {
64 g_print ("could not play\n");
65 return -1;
66 }
67
68 g_print ("sleep 2...\n");
69 g_usleep (2 * G_USEC_PER_SEC);
70
71 g_print ("pause...\n");
72 res = gst_element_set_state (player, GST_STATE_PAUSED);
73 if (res == GST_STATE_CHANGE_FAILURE) {
74 g_print ("could not pause\n");
75 return -1;
76 }
77
78 g_print ("sleep 2...\n");
79 g_usleep (2 * G_USEC_PER_SEC);
80
81 g_print ("play...\n");
82 res = gst_element_set_state (player, GST_STATE_PLAYING);
83 if (res == GST_STATE_CHANGE_FAILURE) {
84 g_print ("could not play\n");
85 return -1;
86 }
87
88 g_print ("sleep 2...\n");
89 g_usleep (2 * G_USEC_PER_SEC);
90
91 g_print ("ready...\n");
92 res = gst_element_set_state (player, GST_STATE_READY);
93 if (res != GST_STATE_CHANGE_SUCCESS) {
94 g_print ("could not play\n");
95 return -1;
96 }
97
98 g_print ("sleep 2...\n");
99 g_usleep (2 * G_USEC_PER_SEC);
100
101 g_print ("play...\n");
102 res = gst_element_set_state (player, GST_STATE_PLAYING);
103 if (res == GST_STATE_CHANGE_FAILURE) {
104 g_print ("could not play\n");
105 return -1;
106 }
107
108 g_main_loop_run (loop);
109
110 return 0;
111 }
112