Rock Out with Your Console Out
Playing and managing your music in text mode.
Some of you probably have played audio files from the terminal with
one-line commands, such as
play, or even used the command line to open
a playlist in a graphical music player. Command-line integration is one
of the many advantages of using Linux software. This is an introduction
for those who want the complete listening experience—browsing, managing
and playing music—without leaving the text console.
Thanks to the Ncurses (New Curses) widget library, developers can design text user interfaces (TUIs) to run in any terminal emulator. An Ncurses application interface is interactive and, depending on the application, can capture events from keystrokes as well as mouse movements and clicks. It looks and works much like a graphical user interface, except it's all ASCII—or perhaps ANSI, depending on your terminal. If you've used GNU Midnight Commander, Lynx or Mutt, you're already familiar with the splendors of Ncurses.
An intuitive interface, whether textual or graphical, is especially
important in a media player. No one wants to sift through a long man
page or resort to Ctrl-c just to stop an annoying song from
playing on repeat, and most users (I'm sure some exceptions exist among
Linux Journal readers) don't want to type out a series of commands just
ls the songs in an album's directory, decide which one
you want to hear and
play it, and then
song in a different directory. If you've ever played music with a purely
command-line application, such as SoX, you know what I'm talking
about. Sure, a single command that plays a file is quite handy; this
article, however, focuses on TUI rather than CLI applications. For many
text-mode programs, Ncurses is the window (no pun intended) to usability.
Note to developers: if you want to write a console music player, take advantage of the Curses Development Kit (CDK), which includes several ready-made widgets, such as scrolling marquees and built-in file browsing.
Now, on to the music players!
Mp3blaster was the first console music player I ever used. That was in 2007, by which time it already was a mature and full-featured application. Its history actually dates back to 1997, before the mainstream really had embraced the MP3 format, let alone the idea of an attractive interface for controlling command-line music playback. Back then, it was humbly known as "Mp3player".
Despite the name, Mp3blaster supports several formats besides MP3s. Currently, these include OGG, WAV and SID. Keep an eye out for FLAC support in the future, as it is on the to-do list in the latest source tarball.
One nice feature of Mp3blaster is the top panel showing important keyboard shortcuts for playlist management. You can scroll through this list using + and -. There is also a useful chart on the right side that shows ASCII art playback symbols (such as |> for play) above their respective shortcut keys. Press ? for detailed help.
You can customize any of the keybindings in your configuration file, which is usually located at ~/.mp3blasterrc. I had to change several of these in order to use Mp3blaster in GNOME due to conflicts with my global hot keys. Mp3blaster's default keybindings are better suited for use without X.
Figure 1. A Playlist in Mp3blaster
Herrie, meaning "clamour" in Dutch, was first released in 2006. Somehow it has escaped mention in many articles on console music players, but the Herrie community group on the music Web site Last.fm shows true fan dedication.
Herrie is great for Last.fm users because it's so easy to set up
track scrobbling. Most of the music players in this article support
scrobbling in some capacity—it's all open-source software, after all,
and in theory, you can write a script to make anything do
configuration is exceptionally simple with Herrie. All you have to do
is put your user name and password in your ~/.herrie/config/herrie.conf
file. Note that the password should not be in plain text; rather, you
should type in the output of
printf %s p4ssw0rd |
as stated in the configuration file itself.
Figure 2. Herrie shows the current playlist on top and a file browser on the bottom.
Music on Console (MOC) is a good choice for music libraries that consist of OGG, WAV and MP3 files. It's easy to use out of the box, boasting a two-paned interface similar to that of Midnight Commander, with a file browser on the left and your playlist on the right. The default keybindings are intuitive—mostly single letters that stand for what they do, such as n for "next track" and R to toggle random play, so command-line newbies need not fear any Emacs-style digital acrobatics.
MOC is my go-to Linux music player these days. It's fast and slick, and it looks just how I want now that I've edited my ~/.moc/config file to adjust the colors and the widths of each window pane. Another plus is its support for the JACK Audio Connection Kit (JACK).
The command to start MOC is
Figure 3. My Customized MOC Layout
Emacs + Bongo/EMMS
If Emacs-style digital acrobatics are your modus operandi, check out Bongo and the Emacs Multi-Media System (EMMS). Both media players run inside Emacs and provide similar functionality. The main difference is that EMMS is designed to run unobtrusively in the background, while Bongo emphasizes the user interface.
Bongo and EMMS are written in Emacs Lisp. You can install them the same way you'd install any other Emacs package; this may vary from distro to distro, but no matter what operating system you're using, you'll probably end up editing some Lisp configuration files. One of the first things to configure is your list of back ends. These programs don't actually do the dirty work of playing your music files; rather, they are front ends for other programs.
You can link any back end of your choice to a file type as well as pass
custom command-line arguments. For example, one of the back ends
Bongo recognizes by default is mpg123. If you want it to use, say, mpg321
instead, it's just a matter of editing that line in your configuration
file or using Emacs to access Bongo's built-in customization dialog with
M-x customize-group RET bongo RET. You can add a custom
back end with a few lines such as these:
(define-bongo-backend mpg321 :pretty-name "MPG-Thr33-Tw0-0ne" :extra-program-arguments '("--loop 0") :matcher '(local-file "mp3" "wav"))
Although I use Emacs from time to time, I'm no guru; I admit that the
time I spent with Bongo was flustering. For instance, I pressed Return
to start playing a track—easy enough—but then realized I didn't know
how to turn it off. I entered
M-x apropos RETURN
read through the list of Bongo commands until I found the one I needed:
M-x bongo-stop. The GitHub home page reveals that
you also can
stop playback immediately with
C-c C-s, and there are
other key combinations for fancier tricks, such as
to stop playback after the next three tracks finish playing.
That example is a fair representation of my whole experience with Bongo so far. It can be scary if you don't know your way around Emacs very well, but it's extremely powerful and full of options that you'd probably never thought of before.
If you're a Vi/Vim fanatic, consider Vimmpc and Vimp3.
Figure 4. An Emacs session with the Bongo player in the bottom window, Bongo's README in the top window and Emacs Code Browser (ECB) on the left side.
Rebecca "Ruji" Chapnik is a freelance creator of miscellanea, including but not limited to text and images. You can find her experiments at http://rujic.net
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems
Join editor Bill Childers and Bit9's Paul Riegle on April 27 at 12pm Central to learn how to keep your Linux systems secure.
Free to Linux Journal readers.Register Now!
- Python Scripts as a Replacement for Bash Utility Scripts
- Considering Legacy UNIX/Linux Issues
- [<Megashare>] Watch Mrs Brown's Boys Movie Online Full Movie HD 2014
- Cluetrain at Fifteen
- Memory Ordering in Modern Microprocessors, Part I
- Getting Good Vibrations with Linux
- New Products
- RSS Feeds
- Security Hardening with Ansible
- diff -u: What's New in Kernel Development