Commit fb4b9071 authored by Cyril Deguet's avatar Cyril Deguet

* playlist.c: better random algorithm: do not play an item if it has

  already been played (check the i_nb_played variable)
  * item.c: initialize i_nb_played to 0
parent d36327cc
......@@ -55,6 +55,7 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
p_item->b_enabled = VLC_TRUE;
p_item->i_group = PLAYLIST_TYPE_MANUAL;
p_item->i_nb_played = 0;
p_item->input.i_duration = -1;
p_item->input.ppsz_options = NULL;
......
......@@ -510,20 +510,33 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
if( b_random )
{
srand( (unsigned int)mdate() );
/* Simple random stuff - we cheat a bit to minimize the chances to
* get the same index again. */
i_arg = (int)((float)p_playlist->i_size * rand() / (RAND_MAX+1.0));
if( i_arg == 0 )
int i_count = 0;
while( i_count < p_playlist->i_size )
{
i_arg = (int)((float)p_playlist->i_size * rand() / (RAND_MAX+1.0));
p_playlist->i_index =
(int)((float)p_playlist->i_size * rand() / (RAND_MAX+1.0));
/* Check if the item has not already been played */
if( p_playlist->pp_items[p_playlist->i_index]->i_nb_played == 0 )
break;
i_count++;
}
if( i_count == p_playlist->i_size )
{
/* The whole playlist has been played: reset the counters */
while( i_count > 0 )
{
p_playlist->pp_items[--i_count]->i_nb_played = 0;
}
if( b_repeat )
if( !b_loop )
{
i_arg = 0;
p_playlist->i_status = PLAYLIST_STOPPED;
}
}
}
else if( !b_repeat )
{
p_playlist->i_index += i_arg;
}
/* Boundary check */
if( p_playlist->i_index >= p_playlist->i_size )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment