3 * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
26 static GstElement *pipeline = NULL;
29 mount_cb (GObject * obj, GAsyncResult * res, gpointer user_data)
34 ret = g_file_mount_enclosing_volume_finish (G_FILE (obj), res, &err);
37 g_print ("mounted successfully\n");
38 gst_bus_set_flushing ((GstBus *) user_data, FALSE);
40 gst_element_set_state (pipeline, GST_STATE_PLAYING);
42 g_print ("mounting failed: %s\n", err->message);
49 message_handler (GstBus * bus, GstMessage * message, gpointer user_data)
52 switch (message->type) {
53 case GST_MESSAGE_ELEMENT:{
54 const GstStructure *s = gst_message_get_structure (message);
55 const gchar *name = gst_structure_get_name (s);
57 if (strcmp (name, "not-mounted") == 0) {
58 GMountOperation *mop = gtk_mount_operation_new (NULL);
60 G_FILE (g_value_get_object (gst_structure_get_value
61 (message->structure, "file")));
63 g_print ("not-mounted\n");
64 gst_element_set_state (pipeline, GST_STATE_NULL);
65 gst_bus_set_flushing (bus, TRUE);
67 g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE,
68 mop, NULL, mount_cb, bus);
79 case GST_MESSAGE_ERROR:{
82 gst_message_parse_error (message, &err, NULL);
83 g_print ("error: %s\n", err->message);
97 main (int argc, char *argv[])
103 g_print ("usage: giosrc-mounting URI\n");
107 gst_init (NULL, NULL);
108 gtk_init (NULL, NULL);
110 pipeline = gst_element_factory_make ("playbin2", NULL);
112 g_object_set (G_OBJECT (pipeline), "uri", argv[1], NULL);
114 bus = gst_element_get_bus (pipeline);
115 watch_id = gst_bus_add_watch (bus, message_handler, NULL);
116 gst_object_unref (bus);
118 gst_element_set_state (pipeline, GST_STATE_PLAYING);
122 g_source_remove (watch_id);
123 gst_element_set_state (pipeline, GST_STATE_NULL);
124 gst_object_unref (pipeline);