March 27, 2006

CLI Magic: Playing music from the command line with mp3blaster

Author: Shashank Sharma

Ever since my first Linux install 10 years ago, I have been hooked on the command line. The Bourne Again Shell (BASH) has been my first choice for moving or copying files, writing text, browsing through my home folder, and lately, even for reading email. When I realized I was depending on graphical players to listen to my MP3 collection, I searched for a command-line MP3 player -- and found mp3blaster.

In addition to MP3 files, mp3blaster can play Ogg and WAV files. The most intriguing things about mp3blaster are its user interface and its ability to make groups within playlists.

Getting started

mp3blaster's highly customizable UI is designed in ncurses, a programming library that allows developers to create text-based interfaces for command-line programs. The ncurses-based interface makes mp3blaster similar to graphical music players, in that there are play, stop, forward, and other buttons. The screen is divided into well-marked boxes. At the top of the screen is a box that lists all the program's keybindings. To browse through all the keybindings, press the plus (+) key to move from page to page.

The box on the right lists the buttons to do routine tasks such as pause, forward, rewind, and play previous track. Each button also has a symbol above it that makes it easier to deduce what the button does what. For example, pressing 6 (>|) makes mp3blaster jump to the next track in your playlist, while pressing 3 (>>) fast-forwards the track.

A simple mp3blaster at the terminal launches mp3blaster and lets you create a playlist. The default keybinding to add files is F1. While this is fine if you run mp3blaster from a text console, most desktop environments have this key mapped to launch the help window, so I suggest you modify the keybindings if you wish to run mp3blaster in X. To do this, copy the sample.mp3blasterrc file from the /usr/share/doc/mp3blaster/example/ directory to your home directory and rename it to .mp3blasterrc; cp /usr/share/doc/mp3blaster/example/sample.mp3blasterrc ~/.mp3blasterrc should do the trick.

Next, edit the .mp3blasterrc file. All the lines in the file are commented out. Scroll down to the section titled keybindings, and uncomment the line #Key.SelectFiles = 1 by removing the # character from the beginning of the line. If you wish to use some other key to add files, replace the 1 after the "=" sign with your key of choice.

Creating playlists

You should use the keybindings menu to create playlists to start, as it takes some time getting acquainted with the keys. Press your Select Files button to open a menu you can use to browse to the directory where you keep your music files. Pressing the Recurs. Select All button adds all the files in the directory to the playlist, as well as files from any subdirectories that mp3blaster finds.

Mp3blaster allows you to create groups in your playlist. To do this, press the Select Files button and browse to your music directory, then press the Add Dirs As Groups" button to create groups in your playlist for each subdirectory.

Each group can have its own shuffle property, meaning you can restrict random song selection to only songs in a single group. If you toggle the shuffle property to "on" from the main playlist, mp3blaster will shuffle songs from all the groups.


The only thing I find lacking in mp3blaster is a jump-to location option. I felt the need for it when, while listening to a two-hour track, I had to jump to the point at 1:15:00. I found the 10-second jump provided by the forward button was too little for this task, as I would have had to keep the forward key pressed for a long time. I solved the problem by modifying the #SkipLength = 10 line from .mp3blasterrc file. A jump-to location option is on the project's TODO list, but until it comes out, modifying the forward time is the best thing to do.

Shashank Sharma is studying for a degree in computer science. He specializes in writing about free and open source software for new users.

Click Here!