Index: monkey-media-player-gst.c
===================================================================
RCS file: /cvs/gnome/monkey-media/src/monkey-media-player-gst.c,v
retrieving revision 1.8
diff -u -b -d -B -r1.8 monkey-media-player-gst.c
--- m-m-orig/src/monkey-media-player-gst.c	1 Feb 2003 17:43:33 -0000	1.8
+++ monkey-media/src/monkey-media-player-gst.c	7 Apr 2003 15:21:52 -0000
@@ -485,63 +485,45 @@
 	return quark;
 }
 
-void
-monkey_media_player_open (MonkeyMediaPlayer *mp,
+static void
+get_decoder (MonkeyMediaPlayer *mp,
 			  const char *uri,
+	     gboolean iradio_mode,
 			  GError **error)
 {
-	gboolean had_sane_pipeline, iradio_mode;
-
-	g_return_if_fail (MONKEY_MEDIA_IS_PLAYER (mp));
-
-	had_sane_pipeline = mp->priv->have_sane_pipeline;
-	mp->priv->have_sane_pipeline = FALSE;
-
-	gst_element_set_state (mp->priv->pipeline,
-			       GST_STATE_NULL);
-
-	g_free (mp->priv->uri);
-	mp->priv->uri = NULL;
-
-	if (uri == NULL) {
-		g_object_set (G_OBJECT (mp->priv->src),
-			      "location", NULL, NULL);
-
-		mp->priv->playing = FALSE;
+	GnomeVFSFileInfo *info;
+	mp->priv->have_type = FALSE;
 
+	if (iradio_mode)
+	{
+		/* FIXME This is hardcoded until GStreamer's
+		 * typefinding stuff is improved. */
+		mp->priv->decoder = gst_element_factory_make ("mad", "decoder");
 		return;
 	}
-
-	/* do the autoplugging */
-	if (had_sane_pipeline && mp->priv->decoder != NULL) {
-		gst_element_unlink_many (mp->priv->src,
-					 mp->priv->decoder,
-					 mp->priv->volume,
-					 NULL);
-
-		gst_bin_remove (GST_BIN (mp->priv->pipeline), mp->priv->decoder);
+	info = gnome_vfs_file_info_new ();
+	if (gnome_vfs_get_file_info (uri, info,
+				     GNOME_VFS_FILE_INFO_DEFAULT | GNOME_VFS_FILE_INFO_GET_MIME_TYPE)
+	    == GNOME_VFS_OK)
+	{
+		if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE)
+		{
+			mp->priv->have_type = TRUE;
+			mp->priv->type = g_strdup (info->mime_type);
+		}
 	}
 
-	mp->priv->have_type = FALSE;
-
-	/* Internet radio support */
-	iradio_mode = !strncmp ("http", uri, 4);
-	g_object_set (G_OBJECT (mp->priv->src),
-		      "iradio-mode", iradio_mode, NULL);
-	g_object_set (G_OBJECT (mp->priv->typefind_src),
-		      "iradio-mode", iradio_mode, NULL);
-
-	g_object_set (G_OBJECT (mp->priv->src),
-		      "location", uri, NULL);
-	g_object_set (G_OBJECT (mp->priv->typefind_src),
-		      "location", uri, NULL);
+	gnome_vfs_file_info_unref (info);
 
+	if (!mp->priv->have_type)
+	{
 	gst_element_set_state (mp->priv->typefind_pipeline,
 			       GST_STATE_PLAYING);
 
 	while (!mp->priv->have_type) {
 		if (!gst_bin_iterate (GST_BIN (mp->priv->typefind_pipeline))) {
-			char *unesc = gnome_vfs_unescape_string_for_display (uri);
+				char *unesc;
+				unesc = gnome_vfs_unescape_string_for_display (uri);
 			g_set_error (error,
 				     MONKEY_MEDIA_PLAYER_ERROR,
 				     MONKEY_MEDIA_PLAYER_ERROR_NO_DEMUX_PLUGIN,
@@ -554,6 +536,7 @@
 
 	gst_element_set_state (mp->priv->typefind_pipeline,
 			       GST_STATE_NULL);
+	}
 
 	mp->priv->decoder = NULL;
 
@@ -576,11 +560,67 @@
 			     MONKEY_MEDIA_PLAYER_ERROR_NO_DEMUX_PLUGIN,
 			     _("Mime type %s not handled; check your installation"),
 			     mp->priv->type);
+	}
+
 		g_free (mp->priv->type);
+}
+
+void
+monkey_media_player_open (MonkeyMediaPlayer *mp,
+			  const char *uri,
+			  GError **error)
+{
+	gboolean had_sane_pipeline, iradio_mode;
+
+	g_return_if_fail (MONKEY_MEDIA_IS_PLAYER (mp));
+
+	had_sane_pipeline = mp->priv->have_sane_pipeline;
+	mp->priv->have_sane_pipeline = FALSE;
+
+	gst_element_set_state (mp->priv->pipeline,
+			       GST_STATE_NULL);
+
+	g_free (mp->priv->uri);
+	mp->priv->uri = NULL;
+
+	if (uri == NULL) {
+		GValue value = {0,};
+		g_value_set_string (&value, NULL);
+		g_object_set (G_OBJECT (mp->priv->src),
+			      "location", &value, NULL);
+
+		mp->priv->playing = FALSE;
+
 		return;
 	}
 
-	g_free (mp->priv->type);
+	/* do the autoplugging */
+	if (had_sane_pipeline && mp->priv->decoder != NULL) {
+		gst_element_unlink_many (mp->priv->src,
+					 mp->priv->decoder,
+					 mp->priv->volume,
+					 NULL);
+
+		gst_bin_remove (GST_BIN (mp->priv->pipeline), mp->priv->decoder);
+	}
+
+	mp->priv->have_type = FALSE;
+
+	/* Internet radio support */
+	iradio_mode = !strncmp ("http", uri, 4);
+	g_object_set (G_OBJECT (mp->priv->src),
+		      "iradio-mode", iradio_mode, NULL);
+	g_object_set (G_OBJECT (mp->priv->typefind_src),
+		      "iradio-mode", iradio_mode, NULL);
+
+	g_object_set (G_OBJECT (mp->priv->src),
+		      "location", uri, NULL);
+	g_object_set (G_OBJECT (mp->priv->typefind_src),
+		      "location", uri, NULL);
+
+	get_decoder (mp, uri, iradio_mode, error);
+	if (*error != NULL)
+		return;
 
 	mp->priv->uri = g_strdup (uri);
 
@@ -645,6 +685,9 @@
 monkey_media_player_pause (MonkeyMediaPlayer *mp)
 {
 	g_return_if_fail (MONKEY_MEDIA_IS_PLAYER (mp));
+
+	if (!mp->priv->playing)
+		return;
 
 	mp->priv->playing = FALSE;
 
