Movieplayer random play & playlist

Wünsche, Anträge, Fehlermeldungen
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Did that, I have that under control - Tested over 50 times before with movieplayer.cpp changes :wink:

killall -9 start_neutrino
killall -9 neutrino
/tmp/neutrino -u

The menu has very large fonts and mixed up menu items (For example no Settings or Services showing in the DBox menu) Is there another file somewhere I have to declare these variables esp the locale stuff?? I have grepped through the source...
Tommy
Tuxboxer
Tuxboxer
Beiträge: 4332
Registriert: Dienstag 7. Mai 2002, 17:04

Re: Movieplayer random play & playlist

Beitrag von Tommy »

u have the "locale" in alphabetical order?
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Yes I noticed that and had that correct see below

Code: Alles auswählen

filebrowser.nextpage Next Page
filebrowser.prevpage Prev. Page
filebrowser.scan Scanning folder
filebrowser.select Select
filebrowser.showrights Show File Permissions
filebrowser.shuffle.active Shuffle On
filebrowser.shuffle.inactive Shuffle Off
filebrowser.sort.date (date)
filebrowser.sort.name (filename)
filebrowser.sort.namedirsfirst (filename2)
filebrowser.sort.size (Size)
filebrowser.sort.type (type)
I have recreated the error 3 times, including downloading new CVS and building files again. If I just add movplayer.cpp, no problems, others then the menu blows.

If you check the diffs in the earlier post you will see there are only 5 line changes, and all are consistent in syntax with similar lines in the files, which makes me guess it might be something not ported in the neutrino patch that is causing it.
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Could someone (when possible) try the three diffs (not including the MP one) and let me know if you get the same error?
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Oh I just noticed in the Diff for MP above; the line

Code: Alles auswählen

+            // allow_random == true;
Should read

Code: Alles auswählen

+            allow_random == true;
If anyone wants to try it out.

I had it commented out whilst I was testing the locale menu options (that still doesnt work :( )
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Below is a new Diff to enable a Music Video shuffle play in MP

Changes are:

New bool allow_random - Set to True - This needs making an option in the MP GUI (beyond me)
Random play TS with no repeat tracking up to apprx 120 videos
Random play VLC with no repeat tracking up to apprx 120 videos
Removed 'Buffering approx. 3 seconds' from the end of VLC played items
Set the end of file buffering timeout to 4 seconds (instead of between 8 and 12 seconds previously)



I am occasionally getting a 'Segmentation fault' when playing file lists and am not sure if this is a known fault or perhaps I have introduced it, any feedback appreciated.

Code: Alles auswählen

cvs: WARNING: Read-only repository access mode selected via `cvs -R'.
Using this option to access a repository which some users write to may
cause intermittent sandbox corruption.
Index: movieplayer.cpp
===================================================================
RCS file: /cvs/tuxbox/apps/tuxbox/neutrino/src/gui/movieplayer.cpp,v
retrieving revision 1.158
diff -U3 -r1.158 movieplayer.cpp
--- a/movieplayer.cpp	9 Dec 2007 23:30:53 -0000	1.158
+++ b/movieplayer.cpp	2 Feb 2008 22:32:05 -0000
@@ -149,6 +149,9 @@
 #endif /* __USE_FILE__OFFSET64 */
 ringbuffer_t *ringbuf;
 bool bufferfilled;
+bool allow_random=true;
+int it_cnt;
+std::string played;
 int streamingrunning;
 unsigned short pida, pidv,pidt;
 short ac3;
@@ -859,7 +862,7 @@
 	printf ("[movieplayer.cpp] Now VLC is sending. Read sockets created\n");
 	hintBox->hide ();
 	bufferingBox->paint ();
-	printf ("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+	printf ("[movieplayer.cpp] Buffering a approx. 3 seconds\n");
 
 	int size;
 	streamingrunning = 1;
@@ -956,7 +959,7 @@
 				if(g_playstate == CMoviePlayerGui::PLAY)
 				{
 					nothingreceived++;
-					if(nothingreceived > (buffer_time + 3)*100) // wait at least buffer time secs +3 to play buffer when stream ends
+					if(nothingreceived > 4*100) // wait at least secs +4 to play buffer when stream ends
 					{
 						printf ("[movieplayer.cpp] ReceiveStreamthread: Didn't receive for a while. Stopping.\n");
 						g_playstate = CMoviePlayerGui::STOPPED;
@@ -1145,7 +1148,7 @@
 				case CMoviePlayerGui::RESYNC:
 					printf ("[movieplayer.cpp] Resyncing\n");
 					ioctl (dmxa, DMX_STOP);
-					printf ("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+					printf ("[movieplayer.cpp] Buffering b approx. 3 seconds\n");
 					/*
 					 * always call bufferingBox->paint() before setting bufferfilled to false
 					 * to ensure that it is painted completely before bufferingBox->hide()
@@ -1160,14 +1163,14 @@
 				case CMoviePlayerGui::PLAY:
 					if(len < MINREADSIZE)
 					{
-						printf("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+						printf("[movieplayer.cpp] Buffering c approx. 3 seconds\n");
 						/*
 						 * always call bufferingBox->paint() before setting bufferfilled to false
 						 * to ensure that it is painted completely before bufferingBox->hide()
 						 * might be called by ReceiveStreamThread (otherwise the hintbox's window
 						 * variable is deleted while being used)
 						 */
-						bufferingBox->paint();
+						// bufferingBox->paint();
 						bufferfilled = false;
 
 					}
@@ -1661,11 +1664,11 @@
   //-----------------------------------
   for(;;)
   {
-	if (isTerminated) return NULL;  // abort
-	
 	//-- check low level ... --  
 	if ( level < 2 )
-	{	
+	{
+		if (isTerminated) return NULL;  // abort
+	
 		//-- ... and freeze playback --
   		if (!freezed)
   		{
@@ -1681,6 +1684,8 @@
 	//-- in freezed state --
 	else if (freezed)
 	{
+		if (isTerminated) return NULL;  // abort
+
 		//-- wait for buffer filled or ... --
 		if ( level < nSegsOpt )
 		{
@@ -2523,7 +2528,7 @@
 		else if(!memcmp(ctx->tmpBuf, MP_PLAYLST_MAGIC, sizeof(MP_PLAYLST_MAGIC)-1))
 		{
 			char *s2;
-			
+			fprintf(stderr, "[mp] Playlist a?\n");
 			while(fgets(ctx->tmpBuf, buffer_size, fp))
 			{
 				if( (s2 = strchr(ctx->tmpBuf,'#')) != NULL )	*s2 = '\0';
@@ -3023,8 +3028,66 @@
 				//-- eventually activate autoplay for next file in a playlist --
 				if( (ctx->itChanged == false) && ctx->lst_cnt )
 				{
-					ctx->it++;
-					if(ctx->it < ctx->lst_cnt)	ctx->itChanged = true;
+				//Hardcoded to test only; want a MP setting in conf- Jan08
+				// allow_random == true;
+				fprintf(stderr, "[mp] BoolRandom? = [%d]\n", allow_random );
+				//Can I add a new MP Setting to the .conf file? - Jan08
+					if (!allow_random)
+					{
+						ctx->it++;
+						if(ctx->it < ctx->lst_cnt)   ctx->itChanged = true;
+						fprintf(stderr, "[mp] Sequential Playlist Item = [%d]\n", ctx->it );
+					}
+					else
+					{
+					//-- This will play random files indefinitely without repeats until [Home key] to exit
+						srand(time(0));
+						// generates random number between 1 and lst_cnt - Jan08
+						std::string str_it;
+						std::string it_check;
+						int loc;
+						bool find_unique = false;
+						// Make playlist item unique - No repeats until all played once
+						// Builds a string of used indexes and then checks instring.
+						while(!find_unique) {
+							ctx->it = rand() % (ctx->lst_cnt-1) + 1;
+							// Conv Int To Sting and Concatenate a unique identifier for search in string
+							std::stringstream ss;
+							ss << ctx->it;
+							ss << "A";
+							it_check = ss.str();
+							it_cnt++;
+							fprintf(stderr, "[mp] it_cnt = [%d]\n", it_cnt );
+							// Start played with identifier
+							if (it_cnt ==1 ) {
+								played = "A";
+							}
+							// Reset played after all tracks played
+							if (it_cnt > (ctx->lst_cnt-1) ) {
+								played = "A";
+								it_cnt = 1;
+							}
+							fprintf(stderr, "[mp] Check is Unique it = [%s]\n", it_check.c_str() );
+							// find in string if played before
+							loc = played.find("A"+it_check, 0);
+							fprintf(stderr, "[mp] -1 is unique = [%d]\n", loc );
+								if ( loc == -1 || it_cnt == (ctx->lst_cnt-1)) {   // && it_cnt == (ctx->lst_cnt-1)
+								find_unique = true;
+								fprintf(stderr, "[mp] Is unique\n");
+								} else {
+								it_check = "";
+								}
+						}
+						ctx->itChanged = true;
+						fprintf(stderr, "[mp] Random playlist item = [%d]\n", ctx->it );
+						// No Repeat - Simply build string of played items with pattern ID wrapping
+						played = played + it_check;
+						// Prevent string overflow (Random files in blocks of 120 tracks effectively)
+						if (played.length() > 245) {
+						played = "A";
+						}
+						fprintf(stderr, "[mp] Played items = [%s]\n", played.c_str() );
+					}
 				}
 				close(ctx->inFd);
 			}
@@ -4050,27 +4113,96 @@
 	do
 	{
 		if (g_playstate == CMoviePlayerGui::STOPPED && !cdDvd) {
-            if(selected + 1 < filelist.size() && !aborted) {
-                selected++;
-				filename = filelist[selected].Name.c_str();
-				sel_filename = filelist[selected].getFileName();
-				//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
-				int namepos = filelist[selected].Name.rfind("vlc://");
-				std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
-                char *tmp = curl_escape (mrl_str.c_str (), 0);
-                strncpy (mrl, tmp, sizeof (mrl) - 1);
-                curl_free (tmp);
-				printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
-
-				update_info = true;
-				start_play = true;
-			} else {
-                open_filebrowser = true;
-                aborted = false;
-            }
+            if(selected + 1 < filelist.size() && !aborted || !allow_random) {
+		int theFileSize = filelist.size();
+		printf ("[movieplayer.cpp] PLaylist Size: %d\n", theFileSize);  //Ozbodd
+		if (!allow_random)
+		{
+			selected++;
+					filename = filelist[selected].Name.c_str();
+					sel_filename = filelist[selected].getFileName();
+					//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
+					int namepos = filelist[selected].Name.rfind("vlc://");
+					std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
+			char *tmp = curl_escape (mrl_str.c_str (), 0);
+			strncpy (mrl, tmp, sizeof (mrl) - 1);
+			curl_free (tmp);
+					printf ("[movieplayer.cpp] Selected No: %d\n", selected);  //Ozbodd
+					printf ("[movieplayer.cpp] Generated a FILE MRL: %s\n", mrl);
+	
+					update_info = true;
+					start_play = true;
+		} 
+		else
+		{
+		//-- This will play random files indefinitely without repeats until [Home key] to exit
+			srand(time(0));
+			// generates random number between 1 and lst_cnt - Jan08
+			std::string str_it;
+			std::string it_check;
+			int loc;
+			bool find_unique = false;
+			if (selected == 0 ) {played = "";it_cnt = 0;}
+			// Make playlist item unique - No repeats until all played once
+			// Builds a string of used indexes and then checks instring.
+			while(!find_unique) {
+				selected = rand() % (theFileSize-1) + 1;
+				// Conv Int To Sting and Concatenate a unique identifier for search in string
+				std::stringstream ss;
+				ss << selected;
+				ss << "A";
+				it_check = ss.str();
+				it_cnt++;
+				fprintf(stderr, "[mp] it_cnt = [%d]\n", it_cnt );
+				// Start played with identifier
+				if (it_cnt == 1 ) {
+					played = "A";
+				}
+				// Reset played after all tracks played
+				if (it_cnt > (theFileSize-1) ) {
+					played = "A";
+					it_cnt = 1;
+				}
+				fprintf(stderr, "[mp] Check is Unique it = [%s]\n", it_check.c_str() );
+				// find in string if played before
+				loc = played.find("A"+it_check, 0);
+				fprintf(stderr, "[mp] -1 is unique = [%d]\n", loc );
+					if ( loc == -1 || it_cnt == (theFileSize-1)) {
+					find_unique = true;
+					fprintf(stderr, "[mp] Is unique\n");
+					} else {
+					it_check = "";
+					}
+			}
+			fprintf(stderr, "[mp] Random playlist item = [%d]\n", selected );
+			// No Repeat - Simply build string of played items with pattern ID wrapping
+			played = played + it_check;
+			// Prevent string overflow (Random files in blocks of 120 tracks effectively)
+			if (played.length() > 245) {
+			played = "A";
+			}
+			fprintf(stderr, "[mp] Played items = [%s]\n", played.c_str() );
+			filename = filelist[selected].Name.c_str();
+					sel_filename = filelist[selected].getFileName();
+					//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
+					int namepos = filelist[selected].Name.rfind("vlc://");
+					std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
+			char *tmp = curl_escape (mrl_str.c_str (), 0);
+			strncpy (mrl, tmp, sizeof (mrl) - 1);
+			curl_free (tmp);
+					printf ("[movieplayer.cpp] Selected No: %d\n", selected);  //Ozbodd
+					printf ("[movieplayer.cpp] Generated a FILE MRL: %s\n", mrl);
+	
+					update_info = true;
+					start_play = true;
+		}
+            }else {
+			open_filebrowser = true;
+			aborted = false;
 
 
 		}
+	}
 		
 		if(exit)
 		{
@@ -4132,7 +4264,7 @@
                     char *tmp = curl_escape (mrl_str.c_str (), 0);
                     strncpy (mrl, tmp, sizeof (mrl) - 1);
                     curl_free (tmp);
-					printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
+					printf ("[movieplayer.cpp] Generated b FILE MRL: %s\n", mrl);
 
 					update_info = true;
 					start_play = true;
@@ -4339,7 +4471,7 @@
                 char *tmp = curl_escape (mrl_str.c_str (), 0);
                 strncpy (mrl, tmp, sizeof (mrl) - 1);
                 curl_free (tmp);
-				printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
+				printf ("[movieplayer.cpp] Generated c FILE MRL: %s\n", mrl);
 
 				update_info = true;
 				start_play = true;
@@ -4357,7 +4489,7 @@
                 char *tmp = curl_escape (mrl_str.c_str (), 0);
                 strncpy (mrl, tmp, sizeof (mrl) - 1);
                 curl_free (tmp);
-				printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
+				printf ("[movieplayer.cpp] Generated d FILE MRL: %s\n", mrl);
 
 				update_info = true;
 				start_play = true;
seife
Developer
Beiträge: 4189
Registriert: Sonntag 2. November 2003, 12:36

Re: Movieplayer random play & playlist

Beitrag von seife »

ozbodd hat geschrieben:I am occasionally getting a 'Segmentation fault' when playing file lists and am not sure if this is a known fault or perhaps I have introduced it, any feedback appreciated.

Code: Alles auswählen

@@ -1160,14 +1163,14 @@
 				case CMoviePlayerGui::PLAY:
 					if(len < MINREADSIZE)
 					{
-						printf("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+						printf("[movieplayer.cpp] Buffering c approx. 3 seconds\n");
 						/*
 						 * always call bufferingBox->paint() before setting bufferfilled to false
 						 * to ensure that it is painted completely before bufferingBox->hide()
 						 * might be called by ReceiveStreamThread (otherwise the hintbox's window
 						 * variable is deleted while being used)
 						 */
-						bufferingBox->paint();
+						// bufferingBox->paint();
 						bufferfilled = false;
 
 					}
There is even a comment telling you that you must not do that - and that it will lead to a segfault. So no wonder it actually happens :-)

From a first look, and from comparing it with the audioplayer code, this looks like an awful lot of code. The audioplayer just takes the playlist and shuffles it randomly. I'm not sure what your code does, it was too long to review quickly ;-)
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

LOL - I am an amature ;) and I know its not pretty - Really just learning stuff here and trying something I wanted in the box, I understand it is very low priority or perhaps even not desired.

I couldn't work out how audioplayer did it, so I tried randomising the call to the array indexes just before the file is played. Where it gets so convoluted is how I am tracking repeat plays by storing indexes in a string and searching that string on each pass for previously played numbers. (I kinda like the unpredictability of somethig that is random just before it plays rather than a preflight list. In audioplayer you could see what was coming in the next 25 tracks, though that wouldn't be an issue with videos.)

The code is the pretty much the same for VLC and TS so could be put in a function or somthing like for both, when I figure out how you do that in c++

I did read the comment about the buffering I interpreted differently :oops: I did suspect it, I'll put that back in and find where the buffering message output. Thanks Seife. I'll also clean up the comments and make them more descriptive.

I'd like to get to understand this code well and eventually look at how we could make both AP and MP like a Jukebox, where you could call up the filebrowser whilst it is playing and add up to 5 tracks to the playlist, with the screen showing now and next, when the playlist is empty it would then play random tracks. I think this is feasible.
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Ok I have tidied it up quite a bit - Changes are

Made a function for the random track generator - Now both TS and VLC share code :o) - Thanks @Seife for the critique that made me learn functions and get some understanding about scope...
VLC will start with a randomised track (TS files will randmise after 1st track in the playlist is played - until I find where it starts...)

allow_random is still hard coded for when multi-select is true in MP Settings - Can anyone help with getting allow_random into the MP settings?

Code: Alles auswählen

cvs: WARNING: Read-only repository access mode selected via `cvs -R'.
Using this option to access a repository which some users write to may
cause intermittent sandbox corruption.
Index: movieplayer.cpp
===================================================================
RCS file: /cvs/tuxbox/apps/tuxbox/neutrino/src/gui/movieplayer.cpp,v
retrieving revision 1.158
diff -U3 -r1.158 movieplayer.cpp
--- a/movieplayer.cpp	9 Dec 2007 23:30:53 -0000	1.158
+++ b/movieplayer.cpp	8 Feb 2008 20:57:37 -0000
@@ -149,6 +149,9 @@
 #endif /* __USE_FILE__OFFSET64 */
 ringbuffer_t *ringbuf;
 bool bufferfilled;
+bool allow_random=true;
+int it_cnt;
+std::string played;
 int streamingrunning;
 unsigned short pida, pidv,pidt;
 short ac3;
@@ -214,7 +217,63 @@
     }
     return false;
 }
+//------------------------------------------------------------------------Ozbodd
+int get_next_random_playlist_item(int playlist_cnt, bool playType, int random_select)
+{
+	//-- This will play random TS or VLC files indefinitely without repeats until [Home key] to exit
+	srand(time(0));
+	std::string str_it;
+	std::string it_check;
+	int loc;
+	bool find_unique = false;
+	it_cnt = 0;
+	// Using a Char String to keep track of played track numbers, delimitered by Char 'A'
+	if ( random_select < 1 ){ 
+		played = "A"; 
+		fprintf(stderr, "[mp] New list reset pattern to [%s]\n", played.c_str() );
+	}
+	// Make playlist item unique - No repeats until all played once
+	while(!find_unique) {
+		// generate random number between 1 and Play List Size - 1
+		random_select = rand() % (playlist_cnt-1)+1;
+		// Conv Int To Sting - random_select
+		std::stringstream ss;
+		ss << random_select;
+		// Add a pattern delimeter to string eg A%random_select1%A%random_select2%A
+		ss << "A";
+		// %it_check% used to check pattern in the string %played%
+		it_check = ss.str();		
+		fprintf(stderr, "[mp] Check track No [%d] is random \n", random_select );
+
+		// If all playlist items played reset string pattern
+		if (it_cnt == (playlist_cnt-1) ) {
+			played = "A";
+			it_cnt = 0;
+		}
+		fprintf(stderr, "[mp] Check is Unique it = [%s]\n", it_check.c_str() );
+		// find pattern %it_check% in string %played% to see if played before
+		loc = played.find("A"+it_check, 0);
+		fprintf(stderr, "[mp] -1 is returned when unique = [%d]\n", loc );
+			if ( loc == -1 ) {
+			find_unique = true;
+			it_cnt++;
+			fprintf(stderr, "[mp] Track is unique\n");
+			} else {
+			it_check = "";
+			}
+	}
+	fprintf(stderr, "[mp] Random playlist item = [%d]\n", random_select );
+	// No Repeat string - Simply append string of played items (##) with pattern A##A##A##A##A etc
+	played = played + it_check;
+	// Prevent string overflow ( MP should play random files in blocks of apprx 120 tracks )
+	if (played.length() > 245) {
+	played = "A";
+	}
+	fprintf(stderr, "[mp] Played items = [%s]\n", played.c_str() );
+
 
+return random_select;
+}
 //------------------------------------------------------------------------
 int get_next_movie_info_bookmark_pos_sec(MI_MOVIE_INFO* movie_info, int pos_sec, bool direction)
 {
@@ -859,7 +918,7 @@
 	printf ("[movieplayer.cpp] Now VLC is sending. Read sockets created\n");
 	hintBox->hide ();
 	bufferingBox->paint ();
-	printf ("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+	printf ("[movieplayer.cpp] Buffering a approx. 3 seconds\n");
 
 	int size;
 	streamingrunning = 1;
@@ -956,7 +1015,7 @@
 				if(g_playstate == CMoviePlayerGui::PLAY)
 				{
 					nothingreceived++;
-					if(nothingreceived > (buffer_time + 3)*100) // wait at least buffer time secs +3 to play buffer when stream ends
+					if(nothingreceived > 4*100) // wait at least secs +4 to play buffer when stream ends
 					{
 						printf ("[movieplayer.cpp] ReceiveStreamthread: Didn't receive for a while. Stopping.\n");
 						g_playstate = CMoviePlayerGui::STOPPED;
@@ -1145,7 +1204,7 @@
 				case CMoviePlayerGui::RESYNC:
 					printf ("[movieplayer.cpp] Resyncing\n");
 					ioctl (dmxa, DMX_STOP);
-					printf ("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+					printf ("[movieplayer.cpp] Buffering b approx. 3 seconds\n");
 					/*
 					 * always call bufferingBox->paint() before setting bufferfilled to false
 					 * to ensure that it is painted completely before bufferingBox->hide()
@@ -1160,7 +1219,7 @@
 				case CMoviePlayerGui::PLAY:
 					if(len < MINREADSIZE)
 					{
-						printf("[movieplayer.cpp] Buffering approx. 3 seconds\n");
+						printf("[movieplayer.cpp] Buffering c approx. 3 seconds\n");
 						/*
 						 * always call bufferingBox->paint() before setting bufferfilled to false
 						 * to ensure that it is painted completely before bufferingBox->hide()
@@ -1661,11 +1720,11 @@
   //-----------------------------------
   for(;;)
   {
-	if (isTerminated) return NULL;  // abort
-	
 	//-- check low level ... --  
 	if ( level < 2 )
-	{	
+	{
+		if (isTerminated) return NULL;  // abort
+	
 		//-- ... and freeze playback --
   		if (!freezed)
   		{
@@ -1681,6 +1740,8 @@
 	//-- in freezed state --
 	else if (freezed)
 	{
+		if (isTerminated) return NULL;  // abort
+
 		//-- wait for buffer filled or ... --
 		if ( level < nSegsOpt )
 		{
@@ -2523,7 +2584,7 @@
 		else if(!memcmp(ctx->tmpBuf, MP_PLAYLST_MAGIC, sizeof(MP_PLAYLST_MAGIC)-1))
 		{
 			char *s2;
-			
+			fprintf(stderr, "[mp] Playlist a?\n");
 			while(fgets(ctx->tmpBuf, buffer_size, fp))
 			{
 				if( (s2 = strchr(ctx->tmpBuf,'#')) != NULL )	*s2 = '\0';
@@ -3023,8 +3084,21 @@
 				//-- eventually activate autoplay for next file in a playlist --
 				if( (ctx->itChanged == false) && ctx->lst_cnt )
 				{
-					ctx->it++;
-					if(ctx->it < ctx->lst_cnt)	ctx->itChanged = true;
+				fprintf(stderr, "[mp] BoolRandom? = [%d]\n", allow_random );
+					//I don't know how to add a new config to MoviePlayer so allow_random is hard coded at present in line 152
+					if (!allow_random)
+					{
+						ctx->it++;
+						if(ctx->it < ctx->lst_cnt)   ctx->itChanged = true;
+						fprintf(stderr, "[mp] Sequential Playlist Item = [%d]\n", ctx->it );
+					}
+					else
+					{
+					// Call function for random play-----------------------------Ozbodd
+						if (ctx->it == 0) {played = "";}
+						ctx->it = get_next_random_playlist_item(ctx->lst_cnt, true, ctx->it);
+						ctx->itChanged = true;
+					}
 				}
 				close(ctx->inFd);
 			}
@@ -4050,27 +4124,53 @@
 	do
 	{
 		if (g_playstate == CMoviePlayerGui::STOPPED && !cdDvd) {
-            if(selected + 1 < filelist.size() && !aborted) {
-                selected++;
-				filename = filelist[selected].Name.c_str();
-				sel_filename = filelist[selected].getFileName();
-				//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
-				int namepos = filelist[selected].Name.rfind("vlc://");
-				std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
-                char *tmp = curl_escape (mrl_str.c_str (), 0);
-                strncpy (mrl, tmp, sizeof (mrl) - 1);
-                curl_free (tmp);
-				printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
-
-				update_info = true;
-				start_play = true;
-			} else {
-                open_filebrowser = true;
-                aborted = false;
-            }
+            if(selected + 1 < filelist.size() && !aborted || !allow_random) {
+		int theFileSize = filelist.size();
+		printf ("[movieplayer.cpp] PLaylist Size: %d\n", theFileSize);  //Ozbodd
+		if (!allow_random)
+		{
+			selected++;
+					filename = filelist[selected].Name.c_str();
+					sel_filename = filelist[selected].getFileName();
+					//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
+					int namepos = filelist[selected].Name.rfind("vlc://");
+					std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
+			char *tmp = curl_escape (mrl_str.c_str (), 0);
+			strncpy (mrl, tmp, sizeof (mrl) - 1);
+			curl_free (tmp);
+					printf ("[movieplayer.cpp] Selected No: %d\n", selected);  //Ozbodd
+					printf ("[movieplayer.cpp] Generated a FILE MRL: %s\n", mrl);
+	
+					update_info = true;
+					start_play = true;
+		} 
+		else
+		{
+		// Call function for random VLC play ------------------------------------------Ozbodd
+			if (selected == 0) {played = "";}
+			selected = get_next_random_playlist_item(theFileSize, false, selected);
+		//-----------------------------------------------------------------------------
+			filename = filelist[selected].Name.c_str();
+					sel_filename = filelist[selected].getFileName();
+					//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
+					int namepos = filelist[selected].Name.rfind("vlc://");
+					std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
+			char *tmp = curl_escape (mrl_str.c_str (), 0);
+			strncpy (mrl, tmp, sizeof (mrl) - 1);
+			curl_free (tmp);
+					printf ("[movieplayer.cpp] Selected No: %d\n", selected);  //Ozbodd
+					printf ("[movieplayer.cpp] Generated a FILE MRL: %s\n", mrl);
+	
+					update_info = true;
+					start_play = true;
+		}
+            }else {
+			open_filebrowser = true;
+			aborted = false;
 
 
 		}
+	}
 		
 		if(exit)
 		{
@@ -4122,7 +4222,7 @@
                     filelist.push_back(*file);
                 }
 
-				if(!filelist.empty())
+				if(!filelist.empty() && !allow_random) //Ozbodd
 				{
 					filename = filelist[0].Name.c_str();
 					sel_filename = filelist[0].getFileName();
@@ -4132,7 +4232,25 @@
                     char *tmp = curl_escape (mrl_str.c_str (), 0);
                     strncpy (mrl, tmp, sizeof (mrl) - 1);
                     curl_free (tmp);
-					printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
+					printf ("[movieplayer.cpp] Generated b FILE MRL: %s\n", mrl);
+
+					update_info = true;
+					start_play = true;
+					selected = 0;
+				}
+				else if (!filelist.empty() && allow_random ) {   // Ozbodd Start with random play instead
+			// Call function
+					played = "";
+					selected = get_next_random_playlist_item(filelist.size(), false, 0);
+					filename = filelist[selected].Name.c_str();
+					sel_filename = filelist[selected].getFileName();
+					//printf ("[movieplayer.cpp] sel_filename: %s\n", filename);
+					int namepos = filelist[selected].Name.rfind("vlc://");
+					std::string mrl_str = filelist[selected].Name.substr(namepos + 6);
+                    char *tmp = curl_escape (mrl_str.c_str (), 0);
+                    strncpy (mrl, tmp, sizeof (mrl) - 1);
+                    curl_free (tmp);
+					printf ("[movieplayer.cpp] Generated b FILE MRL: %s\n", mrl);
 
 					update_info = true;
 					start_play = true;
@@ -4339,7 +4457,7 @@
                 char *tmp = curl_escape (mrl_str.c_str (), 0);
                 strncpy (mrl, tmp, sizeof (mrl) - 1);
                 curl_free (tmp);
-				printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
+				printf ("[movieplayer.cpp] Generated c FILE MRL: %s\n", mrl);
 
 				update_info = true;
 				start_play = true;
@@ -4357,7 +4475,7 @@
                 char *tmp = curl_escape (mrl_str.c_str (), 0);
                 strncpy (mrl, tmp, sizeof (mrl) - 1);
                 curl_free (tmp);
-				printf ("[movieplayer.cpp] Generated FILE MRL: %s\n", mrl);
+				printf ("[movieplayer.cpp] Generated d FILE MRL: %s\n", mrl);
 
 				update_info = true;
 				start_play = true;
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Some help please about arrays and joining them.

I am trying to preserve the MP playlist whilst selecting addition tracks to play in filebrowser. I can copy the current playlist to a temp variable with

Code: Alles auswählen

tmp_filelist = filelist;
filelist is a numerical array containg paths to files.

I then want to append whatever filelist contains after the selection is made (RCInput OK in FB) back into tmp_filelist

I know where I need to do this but I cannot figure out how to combine the two arrays together. Any ideas?

The reason I need to do this is because of the following statement in FB - filelist.clear() - It not only clears the playlist but also the enumerated files in filebrowser when navigating between directories. If I just try and bypass it I do get an appended playlist that works but whilst in FB the enumerated files are painted in multiple times.

Is there a associative member of filelist that I could clear just for the enumerated directory files and not the playlist?

Hope that all makes some sense :/
Thank you
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

I think this nut is starting to crack

There are a few changes that I think may interest everyone.

This is what I have so far:

All the changes are effective when Multi_select is turned on and are working for TS only (Though VLC should be the same when I get there.)

In Filebrowser:

Changed behaviour of OK button in Multi-Select to always navigate directories (like in other modes)

Changed behaviour of Yellow button on Directories - Now adds folder and subs to playlist. For files marks them as usual as does OK on files.
***Filebrowser now remembers the order you mark files (yellow or OK) and plays them in that order if sequential play (allow_random=false) Instead of the order they appear in the folder.

You can select files or directories to add to the playlist from different directory levels in one event.

In Moveplayer:

In all playlists (random play (allow_random) or sequential play (!allow_random) ) the last played file from playlist is removed from the playlist (therefore decreasing playlist) Never any repeats and memory saving.

When Jukebox_Mode=true Red button allows adding files to the playlist queue whilst the DBox is playing the queue. Home button exits the playlist.

File contains the diffs, neutrino and a PDF flowchart

****
http://www.mediafire.com/?4jtujzwdmtc
****
Make a folder with some short TS files for testing.

Try:

Playing 1 file - (OK)
Playing multiple files (Yellow then OK)
Adding a directory (Yellow)
Adding a file or files or directory whilst playing (Red)
Try marking files and/or folders in different levels then (OK) either to start MP or whilst playing existing Playlist (Red)

neutrino is set to random play, change line 152 in MP to try sequential (i.e. Jukebox Mode)

Feedback appreciated - Note VLC play will be corrupt as it is work in progress!
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

VLC and TS now working for me :o)

VLC uses same controls as TS

Added a GUI (OK while videos playing) Shows playing video name and the next 5 tracks in queue.

Don't know if anyone else is testing this? It is mostly finished just need to clean up some comments. Works out of the box and is activated when Multi_Select = Yes

Random play is turned off (still hard coded) - Anyone advise how I put a setting into movieplayer.conf and get it in the GUI like Multi_Select??

http://www.mediafire.com/?2jwd2mthd1c
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

Think it is all finished now

Re-wrote it from the ground up and now has settings in the MP settings GUI for Jukebox and Shuffle modes, Thanks @renwich and @nj for the directions, both modes only work if Multiselect is on.

I have managed to keep all the original behaviours for MP when not in these modes (needs testing please)

Includes @Seife's MP fix

**Removed - Used OLD CVS by mistake ***
ozbodd
Interessierter
Interessierter
Beiträge: 94
Registriert: Donnerstag 24. März 2005, 18:25

Re: Movieplayer random play & playlist

Beitrag von ozbodd »

http://www.mediafire.com/?ayizn4vfsmi
The above link is one diff using the latest CVS