Made a function for the random track generator - Now both TS and VLC share code
) - 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;