RFC: Optimizing Random que and Playback in Volumio for Large Music Libraries

I have been using Volumio for years with a music collection of over 60,000 tracks and kept running into two main issues:

Full queue – slowness and repetition
By default, Volumio loads the entire library into its playback queue. When you play in “random” mode, you often hear the same track multiple times per week, while other tracks sometimes don’t play for years. On my Raspberry Pi 4 (4 GB), I also noticed that the MPD server freezes because it has to manage such a huge queue all the time.

Uneven distribution
Since Volumio doesn’t remember which tracks were played recently, a song you just heard can reappear later that same day. A handful of favorite tracks end up playing far too often, while many other tracks never get heard.

To solve this, I developed a procedure that manages both the queue and the play history:


1. Limit the queue to a fixed minimum

Instead of putting every track into the queue, keep the queue at a fixed minimum size (for example, 10 or 50 tracks). As soon as a track finishes and the queue falls below that threshold, the system automatically refills it back up to the minimum. That way, Volumio never has to work with tens of thousands of items at once.

Why?
A small, constant queue ensures smooth playback and prevents freezes or slowdowns caused by an excessively large internal database.


2. Keep a recent play-history log

Each time a track is played, the system writes a record into a separate database or file with a timestamp and the track name (for example, “2025-06-05 14:23:01 | Artist – Title”). This allows you to set a period (for example, 16 weeks) during which a track cannot be selected again.

How it works:

  1. When the queue needs refilling, the system first randomly picks a candidate from the entire music library (literally any format: MP3, FLAC, OGG, WAV, or whatever you have).
  2. Before adding that track to the queue, it checks whether it appears in the recent history (i.e., played within the set period).
  3. If the track is too recent, it is skipped and a new random track is chosen. This way, you’re guaranteed to hear √n different tracks before any reappear.

3. Automatic refilling and cleanup

Each time a track finishes playing:

  • You remove the just-played track from the queue.
  • You write the track (with timestamp) into the history file.
  • You clean out any old records from the history that are older than the set period (for example, 16 weeks).
  • You check if the queue has fallen below the minimum size, and if so, refill it back to that minimum.

This process repeats continuously, so the player keeps running without interruption and Volumio never has to deal with an oversized queue.


4. Option to inject a temporary playlist

You can temporarily interrupt the standard random queue by manually inserting your own playlist. For example:

  1. Create a playlist in Volumio or via a folder selection from a specific folder or genre.
  2. Inject that playlist at the end of the current queue or have it start right after the current track.
  3. Once that playlist finishes, the system automatically resumes the random queue.

This way, during a party you can first play a curated selection and then smoothly switch back to your large random queue without any extra steps in Volumio itself.

This procedure ensures that, in my case, the CPU load is almost always idle and the Raspberry Pi’s temperature remains minimal

– Just my 5 cents :slight_smile: