diff --git a/src/totem-object.c b/src/totem-object.c
index a1ce2fa..dfdc78b 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -912,6 +912,7 @@ totem_action_exit (Totem *totem)
 				CLAMP (vol, 0, 100),
 				NULL);
 		totem_action_save_size (totem);
+		totem_save_position (totem);
 	}
 
 	if (totem->app != NULL)
@@ -1347,8 +1348,7 @@ totem_action_stop (Totem *totem)
 void
 totem_action_play_pause (Totem *totem)
 {
-	if (totem->mrl == NULL)
-	{
+	if (totem->mrl == NULL) {
 		char *mrl, *subtitle;
 
 		/* Try to pull an mrl from the playlist */
@@ -1364,13 +1364,15 @@ totem_action_play_pause (Totem *totem)
 		}
 	}
 
-	if (bacon_video_widget_is_playing (totem->bvw) == FALSE)
-	{
+	if (bacon_video_widget_is_playing (totem->bvw) == FALSE) {
 		bacon_video_widget_play (totem->bvw, NULL);
 		play_pause_set_label (totem, STATE_PLAYING);
 	} else {
 		bacon_video_widget_pause (totem->bvw);
 		play_pause_set_label (totem, STATE_PAUSED);
+
+		/* Save the stream position */
+		totem_save_position (totem);
 	}
 }
 
@@ -1387,6 +1389,9 @@ totem_action_pause (Totem *totem)
 	if (bacon_video_widget_is_playing (totem->bvw) != FALSE) {
 		bacon_video_widget_pause (totem->bvw);
 		play_pause_set_label (totem, STATE_PAUSED);
+
+		/* Save the stream position */
+		totem_save_position (totem);
 	}
 }
 
@@ -1654,8 +1659,8 @@ totem_action_set_mrl_with_warning (Totem *totem,
 {
 	gboolean retval = TRUE;
 
-	if (totem->mrl != NULL)
-	{
+	if (totem->mrl != NULL) {
+		totem_save_position (totem);
 		g_free (totem->mrl);
 		totem->mrl = NULL;
 		bacon_video_widget_close (totem->bvw);
@@ -1663,8 +1668,7 @@ totem_action_set_mrl_with_warning (Totem *totem,
 		play_pause_set_label (totem, STATE_STOPPED);
 	}
 
-	if (mrl == NULL)
-	{
+	if (mrl == NULL) {
 		retval = FALSE;
 
 		play_pause_set_label (totem, STATE_STOPPED);
@@ -1708,6 +1712,7 @@ totem_action_set_mrl_with_warning (Totem *totem,
 			autoload_sub = totem_uri_get_subtitle_uri (mrl);
 
 		totem_gdk_window_set_waiting_cursor (totem->win->window);
+		totem_try_restore_position (totem, mrl);
 		retval = bacon_video_widget_open (totem->bvw, mrl, subtitle ? subtitle : autoload_sub, &err);
 		g_free (autoload_sub);
 		gdk_window_set_cursor (totem->win->window, NULL);
@@ -1734,8 +1739,7 @@ totem_action_set_mrl_with_warning (Totem *totem,
 		/* Set the playlist */
 		play_pause_set_label (totem, retval ? STATE_PAUSED : STATE_STOPPED);
 
-		if (retval == FALSE && warn != FALSE)
-		{
+		if (retval == FALSE && warn != FALSE) {
 			char *msg, *disp;
 
 			disp = totem_uri_escape_for_display (totem->mrl);
@@ -1750,8 +1754,7 @@ totem_action_set_mrl_with_warning (Totem *totem,
 			g_free (msg);
 		}
 
-		if (retval == FALSE)
-		{
+		if (retval == FALSE) {
 			if (err)
 				g_error_free (err);
 			g_free (totem->mrl);
diff --git a/src/totem-uri.c b/src/totem-uri.c
index 65efe1f..4fb3952 100644
--- a/src/totem-uri.c
+++ b/src/totem-uri.c
@@ -34,6 +34,15 @@
 #include "totem-uri.h"
 #include "totem-private.h"
 
+/* 5 minute threshold. We don't want to save the position within a 3
+ * minute song for example. */
+#define SAVE_POSITION_THRESHOLD 1 * 60 * 1000
+/* Don't save the position of a stream if we're within 5% of the end so that,
+ * for example, we don't save if the user exits when they reach the credits of a film */
+#define SAVE_POSITION_END_THRESHOLD 0.05
+/* The GIO file attribute used to store the position in a stream */
+#define SAVE_POSITION_FILE_ATTRIBUTE "xattr::Totem.Position"
+
 static GtkFileFilter *filter_all = NULL;
 static GtkFileFilter *filter_subs = NULL;
 static GtkFileFilter *filter_supported = NULL;
@@ -682,3 +691,77 @@ totem_add_files (GtkWindow *parent, const char *path)
 	return filenames;
 }
 
+void
+totem_try_restore_position (Totem *totem, const char *mrl)
+{
+	GFile *file;
+	GFileInfo *file_info;
+	const char *seek_str;
+
+	if (mrl == NULL)
+		return;
+
+	file = g_file_new_for_uri (mrl);
+	g_message ("trying to restore position of: %s", mrl);
+
+	/* Get the file attribute containing the position */
+	file_info = g_file_query_info (file, SAVE_POSITION_FILE_ATTRIBUTE, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+	g_object_unref (file);
+
+	if (file_info == NULL)
+		return;
+
+	seek_str = g_file_info_get_attribute_string (file_info, SAVE_POSITION_FILE_ATTRIBUTE);
+	g_message ("seek time: %s", seek_str);
+	totem->seek_to = g_ascii_strtoull (seek_str, NULL, 0);
+
+	g_object_unref (file_info);
+}
+
+void
+totem_save_position (Totem *totem)
+{
+	gint64 stream_length, position;
+	char *mrl, *pos_str;
+	GFile *file;
+	GError *error = NULL;
+
+	stream_length = bacon_video_widget_get_stream_length (totem->bvw);
+	position = bacon_video_widget_get_current_time (totem->bvw);
+	mrl = totem_get_current_mrl (totem);
+g_message ("save_position called");
+	if (mrl == NULL)
+		return;
+
+	/* Don't save if it's:
+	 *  - a live stream
+	 *  - too short to make saving useful
+	 *  - too close to the end to make saving useful
+	 */
+	if (stream_length < SAVE_POSITION_THRESHOLD ||
+	    (stream_length - position) < stream_length * SAVE_POSITION_END_THRESHOLD) {
+		g_message ("not saving position because the video/track is too short");
+		g_free (mrl);
+		return;
+	}
+
+	g_message ("saving position: %"G_GINT64_FORMAT, position);
+
+	file = g_file_new_for_uri (mrl);
+	g_free (mrl);
+
+	/* Save the position in the stream as a file attribute */
+	pos_str = g_strdup_printf ("%"G_GINT64_FORMAT, position);
+	g_file_set_attribute (file,
+			      SAVE_POSITION_FILE_ATTRIBUTE,
+			      G_FILE_ATTRIBUTE_TYPE_STRING, pos_str,
+			      G_FILE_QUERY_INFO_NONE, NULL, &error);
+	g_free (pos_str);
+
+	if (error != NULL) {
+		g_warning (error->message);
+		g_error_free (error);
+	}
+	g_object_unref (file);
+}
+
diff --git a/src/totem-uri.h b/src/totem-uri.h
index e6514d9..c4d9b41 100644
--- a/src/totem-uri.h
+++ b/src/totem-uri.h
@@ -49,6 +49,9 @@ char *		totem_add_subtitle		(GtkWindow *parent,
 						 const char *path);
 void		totem_add_pictures_dir		(GtkWidget *chooser);
 
+void totem_save_position (Totem *totem);
+void totem_try_restore_position (Totem *totem, const char *mrl);
+
 G_END_DECLS
 
 #endif /* TOTEM_URI_H */
diff --git a/src/totem.c b/src/totem.c
index 0596ff0..1ee4d88 100644
--- a/src/totem.c
+++ b/src/totem.c
@@ -97,7 +97,6 @@ about_url_hook (GtkAboutDialog *about,
 	}
 }
 
-
 static void
 about_email_hook (GtkAboutDialog *about,
 		  const char *email_address,
