Random Playback

Sometime users asks us about AIMP’s random playback mode. In this article, I want to talk about our random playback implementation that used in modern version of AIMP for all supported platforms. Let’s go.

Random queue is not random

At first time, it may seems that random playback mode is so simple to implement, just take a random file from the playlist and play it next. However, you must take into account that random number generator may produce repetitions of one numbers and not produce others numbers at all. This means that some tracks will be played several times, while others will not be played even once. So, what why AIMP uses pseudo-random queue for random playback.

Building the queue

When you activates the “shuffle mode”, app creates a shadow copy of playing playlist (hidden from user), shuffles it and starts playing. The shuffle procedure uses a random number generator whose values are used here as indexes of items to swap.

This approach resolves following issues:

  • All tracks will be played once
  • Code become simpler – app operates with playlists only, plays it from beginning to end
  • We know exactly when the playlist ends
    to jump to next playlist or execute scheduled action
  • Navigation forward/backward through playback history is available

In AIMP for PC, you can view a state of random playback queue, to do this you need (when app is closed) to add the DebugShowPlaybackQueueStatus=1 pair to the [Playlist.Manager] section of AIMP.ini (located in the “profile folder”):

As you can see, second line of each item now contains an additional information: first number is index of the item in random playback queue, second number (in brackets) is index of currently playing item.

In the example, first track will be played 24th in order (23rd, if we count from 0), second track is 10th.

Updating the Queue

Adding the tracks

When you adding new tracks to playlist, the tracks will be added to random playback queue automatically, in random order of course, but strictly after currently playing track. So, you will definitely hear the just added tracks before playlist end.

Start track playback manually

In case, when user intervenes to playback queue, starting another track manually, the track will be moved in the queue to place of next item (after currently playing), regardless of where it was before:

In the example, I’ve started the 4th track, and it index was changed from 37th to 1st. The track has been inserted to 1st place and shifted all other tracks in the queue (1st and 2nd tracks has increased their indexes by 1).

Restart the app

Playback queue stores to playlist file (AIMPPL4 and XSPF file formats). So, restarting the app will not reset playback history and you will able to resume playback after restarting without recreating the queue.

Switching the mode

Switching between playback mode (normal / shuffle) leads the queue to be recreated! It means, that playback history of the randomly played playlist will be lost, and you will start the playlist playing at next time from beginning.

Usually, its happens when user temporary switches to another playlist where shuffle mode is not needed, and turns off the shuffle mode. To avoid playback queue from reset in this case, we recommends to switch on the “each playlist has its own playback mode” option:

  • v5.30 for PC: “settings \ player \ automatic \ playback”
  • v5.11 for PC: “settings \ player \ automatic”
  • v4.05 for Android: “settings \ playback \ navigation”

End of Playlist

Random playback queue will be recreated automatically on repeat the playlist after it has finished.

Sometimes, it may seem that the app start to repeat tracks. Usually it associated with repeating a playlist. The playlist has ended, the player has rebuilt the queue and started playing the playlist from the beginning. However, the tracks that you just recently heard now are at the top of the queue, and therefore the consciousness focuses on this.

Sorting, Removing

and all other playlist operations does not affect to random playback queue.

4 thoughts on “Random Playback

Leave a Reply