vendredi 1 avril 2016

Random / Shuffle playlist

I have a Filtered Table of music Titles and would like to shuffle-play them. I tried using Random, but often the same Title got played before all of the others had been played once.

I tried using a shuffled array (I found the method here) that then called the Record's matching AutoInc value...

procedure Shuffle(anArr : TStringList; aMax : Integer);
var
  i: Integer;
begin
  Randomize;
  for i:=0 to aMax do
    anArr.Add(IntToStr(i));
  for i := anArr.Count-1 downto 1 do
    anArr.Exchange(i,Random(i+1));
end;

But, because the Table is filtered, the AutoInc was not contiguous. I don't want to have to scan the Filtered Table for all available AutoInc values and then shuffle that unless I really have to as the Table could be quite large.

Is there any clever way to random shuffle the playing and not repeat until every Title has been played once? I tried using a Boolean Field in the record to indicate "Played," but then I had to scan the entire Table to clear them all before the next round of shuffled play.

It is possible that that the Filtered Table may be played many times over and I'd like a new shuffled order for each full iteration.




Aucun commentaire:

Enregistrer un commentaire