[PATCH] Skip non-existant files when going to the previous song in the playlist

Marten ter Borgh <[email protected]>
Newsgroups gmane.comp.multimedia.xmms.devel
Message-ID <[email protected]>
I attached this patch in bugzilla (bug #333) already, but since nobody 
noticed, I'm reposting it here.

The patch is against xmms-CVS as it was on 27-12.
With the patch, xmms keeps proceeding to the previous entry in the 
playlist until it finds one that has a readable filelocation or is a 
http:// stream.
I changed the function that handles switching to the _next_ file the 
same way; this doesn't change the behaviour much (it just makes skipping 
over 'dead' files faster), but it makes the two functions look more the 
same, which I think is good for maintainability of the code. This change 
also introduced a null-pointer check to the next-function that only the 
prev-function had previously.

-Marten
playlist.c.diff (text/plain, 2.7 KB)
--- playlist.c	2002-12-27 01:08:23.000000000 +0100
+++ ../playlist.c	2002-12-27 01:14:12.000000000 +0100
@@ -595,18 +595,37 @@
 		restart_playing = TRUE;
 	}
 
-	plist_pos_list = find_playlist_position_list();
-	if (g_list_next(plist_pos_list))
-		playlist_position = plist_pos_list->next->data;
-	else if (cfg.repeat)
+	do
 	{
-		playlist_position = NULL;
-		__playlist_generate_shuffle_list();
-		if (cfg.shuffle)
-			playlist_position = shuffle_list->data;
-		else
-			playlist_position = playlist->data;
-	}
+		plist_pos_list = find_playlist_position_list();
+		
+		if (g_list_next(plist_pos_list))
+			playlist_position = plist_pos_list->next->data;
+		else if (cfg.repeat)
+		{
+			GList *node;
+			node = NULL;
+			playlist_position = NULL;
+			__playlist_generate_shuffle_list();
+			if (cfg.shuffle)
+				node = shuffle_list;
+			else
+				node = playlist;
+			if (node)
+				playlist_position = node->data;
+		}
+
+		if (playlist_position && playlist_position->filename && 
+				strstr(playlist_position->filename, "://"))
+		{break;} 
+		/*we don't want to check if a  http:// stream exists as a file*/
+		
+	} while (playlist_position && playlist_position->filename && 
+			access(playlist_position->filename, R_OK));
+	/*keep on going to the next playlist-item untill we find one that 
+	 * exists as a file*/
+
+	
 	PL_UNLOCK();
 	playlist_check_pos_current();
 
@@ -648,21 +667,36 @@
 		restart_playing = TRUE;
 	}
 	
-	plist_pos_list = find_playlist_position_list();
-	if (g_list_previous(plist_pos_list))
-		playlist_position = plist_pos_list->prev->data;
-	else if (cfg.repeat)
-	{
-		GList *node;
-		playlist_position = NULL;
-		__playlist_generate_shuffle_list();
-		if (cfg.shuffle)
-			node = g_list_last(shuffle_list);
-		else
-			node = g_list_last(playlist);
-		if (node)
-			playlist_position = node->data;
-	}
+	do
+	{
+		plist_pos_list = find_playlist_position_list();
+		
+		if (g_list_previous(plist_pos_list))
+			playlist_position = plist_pos_list->prev->data;
+		else if (cfg.repeat)
+		{
+			GList *node;
+			playlist_position = NULL;
+			__playlist_generate_shuffle_list();
+			if (cfg.shuffle)
+				node = g_list_last(shuffle_list);
+			else
+				node = g_list_last(playlist);
+			if (node)
+				playlist_position = node->data;
+		}
+
+		if (playlist_position && playlist_position->filename && 
+				strstr(playlist_position->filename, "://"))
+		{break;} 
+		/*we don't want to check if a  http:// stream 
+		 * exists as a file: we already know it doesn't*/
+
+	} while (playlist_position && playlist_position->filename && 
+			access(playlist_position->filename, R_OK));
+	/*keep on going to the previous playlist-item untill we find one that 
+	 * exists as a file*/
+		
 	PL_UNLOCK();
 	playlist_check_pos_current();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.