audio_manager
audio_manager copied to clipboard
Fix inconsistent behavior when in shuffle mode
The shuffle mode has a few inconsistent behavior. For example, take the following shuffled indices:
[0]:1
[1]:11
[2]:5
[3]:6
[4]:9
[5]:2
[6]:10
[7]:8
[8]:3
[9]:0
[10]:4
[11]:7
If we are currently playing index 8
, calling previous()
while in shuffle mode will decrement the index by 1 so it becomes 7
, and then we will re-select the index 8
. Instead of generating a shuffled array that can make loops possible or may make it impossible to go back or go forward, we can just generate random indices on the fly instead, while making sure that we don't generate the same index as the currently selected one.
Wouldn't this make some indexes play more frequently, while some don't even have a chance of playing?
Wouldn't this make some indexes play more frequently, while some don't even have a chance of playing?
Hmm that's right, the generator should be initialized only once and reused.