From e87a0231846ca1ef79eff07233025989693131d2 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 5 Jan 2016 09:32:09 +0000 Subject: tracklist: reshuffle tracklist when exhausted For now, shuffle means "random without repeats". So avoid repeating ourselves by shuffling when we've reached the end of the shuffled tracklist and have no more tracks to go. Whenever a client restarts the player or hits the loop for repeat, we'll have a freshly shuffled list for them to listen to. --- lib/dtas/tracklist.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb index 68e88f2..6e0dd75 100644 --- a/lib/dtas/tracklist.rb +++ b/lib/dtas/tracklist.rb @@ -123,10 +123,11 @@ class DTAS::Tracklist # :nodoc: @goto_pos = @goto_off = nil if cur[next_pos] @pos = next_pos - elsif repeat - next_pos = @pos = 0 else - return + # reshuffle the tracklist when we've exhausted it + cur.shuffle! if @shuffle + return unless repeat + next_pos = @pos = 0 end [ cur[next_pos].to_path, next_off ] end -- cgit v1.2.3-24-ge0c7