Album Shuffle, a Random Playlist Generator


I first posted this on 18th February 2007 on my plain HTML site.

Something that has bothered me ever since I got my mp3 player was its inability to play whole albums in “random” order, rather than individual tracks. I’ve often found myself playing the same few albums over and over again and it takes a conscious effort to select something different. This program was the result. It was started as something that I might find useful, but ended up more as a programming exercise.

To solve this problem I’ve written a small application that lists the folders under a specified root, shuffles them and then writes out the files as a simple playlist. This playlist can then be copied to the mp3 player’s playlist folder, and there you go – a “randomised” playlist of albums. It requires the mp3 player to be connected to the PC (of course).

Random playlist Generator Screenshot

Random playlist Generator Screenshot

It’s not brilliant, but it does the job. I’m making it available online to download. I’m not charging for the software, but if you like it I’d appreciate a donation.


It was written in C# using Visual Studio 2008 on top of .NET 3.5 and is (obviously) only available for Windows. The list view and the previous and next buttons (< >) were put in for initial testing purposes, but being lazy I left them in when I got the rest of it working.

There are still things to do, like put in a better application icon, but my graphic design skills are virtually nonexistent so it’ll have to wait until I come across a better one on the web.

So I may well be updating it at some point (but don’t hold your breath) and I may even put the code online too (once I’ve tidied it up). The usual warnings and provisos apply to the program – use at your own risk, there’s no support etc. However, if you have any comments or suggestions then I’d be happy to hear from you.

On 6th March 2007 I made the first update as I found that I had got a duff folder somewhere in my music tree because the application failed with an IOException. The simplest solution was to put in a try...catch block around the offending code. This meant that it would ignore that folder and carry on with the rest of the tree.

On 13th September 2008 I updated the application again. While developing the random album chooser application I found a C# mp3 tag library (TagLib#) which has let me read the necessary information from the files (specifically the length of the track) to generate an m3u file.

On 25th October 2008 I uploaded version 2.0: The application is now multi-threaded. This means that you can now press Stop or hit Esc to cancel the shuffle – most useful if you’ve forgotten to set the search root correctly, which I usually do when running a new version for the first time. The application’s buttons are enabled or disabled appropriately when the state of the application changes.

I’ve recently been looking at Microsoft FxCop and reading up on .NET 3.5 and C# 3 so the code is now in a far tidier state than before. It hasn’t added any new functionality to the application so I haven’t updated the version number, but I have uploaded it as in installer rather than a zip file.

Future enhancements:

  • Look for music file types other than mp3.

© 2009, Chris. All rights reserved. If you republish this post can you please link back to the original post.

,

  1. #1 by Michael on 20 March, 2011 - 5:20 am

    This is a feature I’ve been searching for in my media programs. Upon its use it appears that it’s finding all tracks by the same artist and the same album. I’d suggest using album artist instead.

    Also, the ability to specify more than one file type would be handy, or maybe I’m just not sure how they’re delimited.

    • #2 by Chris on 20 March, 2011 - 2:21 pm

      Michael,

      Thanks for your feedback.

      How have you got your music files organised on your hard drive? It does rely on there being a single root directory with a directory for each artist containing their albums in further sub directories:

      c:\music
      |- artist 1
      | |- album 1
      | |- album 2
      |- artist 2
      | |- album 1
      | |- album 2

      and so on.

      At the moment it only searches for mp3′s as that’s what I use for my music. I did intend to get it to search for other types of music file, but I have never got round to it!.

  2. #3 by Alun on 21 August, 2014 - 9:17 pm

    Hi Chris,

    I’ve looked everywhere for something like this, thanks. However, I seem to have the problem that the album files are listed not in track order.
    I have them named such that the track number is prefixed to the songname, so in a normal alphabetical file display they should display in track order. However they seem to list in random order, which makes it seem that the app simply displays them in the order it finds them from the system api perhaps.
    Anyhow, just thought I would mention that.
    Cheers,
    Alun.

    • #4 by Chris on 22 August, 2014 - 7:15 pm

      Alun,

      I’ve not looked at this code for quite a while now, but as far as I remember it just looks at the filenames when ordering them. This works for me as I have all my music in filenames that have the pattern “nn-title.mp3″ where “nn” is the zero padded track number.

      To work for all cases I’d have to check the files and read the track number from the meta data.

      Chris.

  3. #5 by Kuri on 26 September, 2014 - 5:12 pm

    Hi,

    First of all, I have to thank you for coding this. I searched all day for something similar and was about to give up. This program is absolutely fantastic.

    Can you tell me if it’s possible to filter multiple file types ? I have some flac and mp3 in my collection, it seems I can’t shuffle both (already tried to add multiple filter, doesn’t work, “*.*” filter works but of course adds any other files in the playlist).

    Anyway good piece of work.

    Cheers,

    Kuri

    • #6 by Chris on 26 September, 2014 - 5:34 pm

      Kuri,

      Multiple file types is (or should that be was) on my to do list, but it was one of the things I never got round to.

      Sorry.

      Chris.

(will not be published)
*