1 /* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 * DEALINGS IN THE SOFTWARE.
21 * Alternatively, the contents of this file may be used under the
22 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
23 * which case the following provisions apply instead of the ones
26 * This library is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU Library General Public
28 * License as published by the Free Software Foundation; either
29 * version 2 of the License, or (at your option) any later version.
31 * This library is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 * Library General Public License for more details.
36 * You should have received a copy of the GNU Library General Public
37 * License along with this library; if not, write to the
38 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
39 * Boston, MA 02111-1307, USA.
49 handle_file_or_directory (const gchar
* filename
)
55 if ((dir
= g_dir_open (filename
, 0, NULL
))) {
58 while ((entry
= g_dir_read_name (dir
))) {
61 path
= g_strconcat (filename
, G_DIR_SEPARATOR_S
, entry
, NULL
);
62 handle_file_or_directory (path
);
70 if (g_path_is_absolute (filename
)) {
71 uri
= g_filename_to_uri (filename
, NULL
, &err
);
73 gchar
*curdir
, *absolute_path
;
75 curdir
= g_get_current_dir ();
76 absolute_path
= g_strconcat ( curdir
, G_DIR_SEPARATOR_S
, filename
, NULL
);
77 uri
= g_filename_to_uri (absolute_path
, NULL
, &err
);
78 g_free (absolute_path
);
83 /* great, we have a proper file:// URI, let's play it! */
86 g_warning ("Failed to convert filename '%s' to URI: %s", filename
,
95 main (int argc
, char *argv
[])
97 gchar
**filenames
= NULL
;
98 const GOptionEntry entries
[] = {
99 /* you can add your won command line options here */
100 { G_OPTION_REMAINING
, 0, 0, G_OPTION_ARG_FILENAME_ARRAY
, &filenames
,
101 "Special option that collects any remaining arguments for us" },
108 /* Before calling any GLib or GStreamer function, we must initialise
109 * the GLib threading system */
110 if (!g_thread_supported())
111 g_thread_init (NULL
);
113 ctx
= g_option_context_new ("[FILE1] [FILE2] ...");
114 g_option_context_add_group (ctx
, gst_init_get_option_group ());
115 g_option_context_add_main_entries (ctx
, entries
, NULL
);
117 if (!g_option_context_parse (ctx
, &argc
, &argv
, &err
)) {
118 g_print ("Error initializing: %s\n", GST_STR_NULL (err
->message
));
121 g_option_context_free (ctx
);
123 if (filenames
== NULL
|| *filenames
== NULL
) {
124 g_print ("Please specify a file to play\n\n");
130 num
= g_strv_length (filenames
);
132 for (i
= 0; i
< num
; ++i
) {
133 handle_file_or_directory (filenames
[i
]);
136 g_strfreev (filenames
);