implement seek to, change rate, gui seek bar
[gst-scaletempo-demo-rj.git] / src / demo-main.c
blobc1e50f2473a8569cdb803b70d49f903ab2258937
1 /* main.c
2 * Copyright (C) 2008 Rov Juvano <rovjuvano@users.sourceforge.net>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
22 #include "demo-player.h"
23 #include "demo-gui.h"
25 extern GOptionGroup* gtk_get_option_group (gboolean);
26 extern GOptionGroup* gst_init_get_option_group (void);
28 static void
29 handle_error_message (DemoPlayer *player,
30 const gchar *msg,
31 gpointer data)
33 const gchar *format = (const gchar *)data;
34 g_print (format, msg);
37 static void
38 handle_quit (gpointer source,
39 gpointer data)
41 g_main_loop_quit ((GMainLoop *)data);
45 int
46 main (int argc, char *argv[])
48 gchar **uris = NULL;
49 gchar *filter_name = "identity";
51 const GOptionEntry entries[] = {
52 { "filter", '\0', 0, G_OPTION_ARG_STRING, &filter_name,
53 "filter", "NAME" },
54 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &uris,
55 "Special option that collects any remaining arguments for us" },
56 { NULL, }
59 if (!g_thread_supported ())
60 g_thread_init (NULL);
62 GOptionContext *ctx = g_option_context_new ("uri ...");
63 g_option_context_add_group (ctx, gst_init_get_option_group ());
64 g_option_context_add_group (ctx, gtk_get_option_group (FALSE));
65 g_option_context_add_main_entries (ctx, entries, NULL);
66 GError *err = NULL;
67 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
68 g_print ("Error initializing: %s\n", err->message);
69 g_error_free (err);
70 return -1;
72 g_option_context_free (ctx);
74 if (uris == NULL || *uris == NULL) {
75 g_print ("Please specify a URI to play\n\n");
76 return -1;
79 DemoGui *gui = g_object_new (DEMO_TYPE_GUI, NULL);
80 DemoPlayer *player = g_object_new (DEMO_TYPE_PLAYER, "filter", filter_name, NULL);
81 g_signal_connect (player, "error", G_CALLBACK (handle_error_message), "PLAYER ERROR: %s\n");
82 g_signal_connect (gui, "error", G_CALLBACK (handle_error_message), "GUI ERROR: %s\n");
83 demo_gui_set_player (gui, player);
85 GMainLoop *loop = g_main_loop_new (NULL, FALSE);
86 g_signal_connect (gui, "quiting", G_CALLBACK (handle_quit), loop);
88 int i, num = g_strv_length (uris);
89 GList *uri_list = NULL;
90 for (i=0; i<num; i++) {
91 uri_list = g_list_append (uri_list, uris[i]);
94 demo_gui_show (gui);
95 demo_gui_set_playlist (gui, uri_list);
96 g_main_loop_run (loop);
98 return 0;