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