Command Line Audio players: mpg321 and mpg123
21 February 2006
The classic audio players for the command line are of course mpg321 and mpg123. These two players are more or less identical when it comes to using them. I'm not 100% sure of the historical facts here but it here is the story as I understand it. If you know better then please leave a comment below.
The history of mpg321 and mpg123
mpg123 was one of the first ever mp3 players, but it was under a non-free licence, so mp321 was created to replace it. Later on mpg123 would be released under a free licence too, but by then everyone already had moved over to mpg321 and that seems to be the actively developed one. According to Joe Drew, the author of mpg321:
mpg123 is very popular because of its relative simplicity and its general facility. It is very good at what it does. It is, however, under a non-free license: you can't incorporate its code into your own without getting special permission, and commercial entities also need special permission just to use it.
Being a Free Software advocate, I saw a deficiency in the dependency many people had on mpg123. Therefore, I created mpg321, and as more features of mpg123 are implemented, it becomes less and less likely that anyone will need mpg123 for anything any more.
So let us continue with mpg321.
Using mpg321
Using mpg321 could not be any simplier, you simply type mpg321 and then the name of the file or files that you want to play. Below is mpg321 in action, here I am just using the wildcard to play all the songs in the directory (in alphabetical order):
# mpg321 *
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.59q (2002/03/23). Written and copyrights by Joe Drew.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
Title : Sync or swim Artist: Artemis
Album : Gravity Year : 2005
Comment: Magnatune.com Genre : Pop
Playing MPEG stream from 001_01-Sync or swim-Artemis.mp3 ...
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz stereo
If you do not want all that text output, then use mpg321 -q filename. If you want more info, such as the time remaining etc, then use mpg321 -v.
Using mpg123
As you might expect, mpg123 works exactly the same, apart from the version number and the author, usage is exactly the same.
# mpg123 *
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2 and 3.
Version 0.59s-r9 (2000/Oct/27). Written and copyrights by Michael Hipp.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
Title : Sync or swim Artist: Artemis
Album : Gravity Year : 2005
Comment: Magnatune.com Genre : Pop``
Playing MPEG stream from 001_01-Sync or swim-Artemis.mp3 ...
Found new ID3 Header
MPEG 1.0 layer III, 128 kbit/s, 44100 Hz stereo
Playlists
You may already be thinking to yourself, 'thats nice but what about playlists?' Well mpg321 has fantastic playlist support. To create a playlist just make a text file of your songs. For example, this is how I do it:
ls *.mp3 > songs.playlist.txt
ls | grep Artemis > artemis.playlist.txt
You can then edit the order using your favourite text editor, e.g. Emacs/Vi/Nano.
To play the list just use the --list or -@ option:
mpg321 --list artemis.txt
Life is Random
To make things more fun, mpg321 has two shuffle modes; little shuffle and big shuffle.
In little shuffle mode, mpg321 plays every file once in a random order. So it sorts the files you have specified (directly or through playlists) and produces a random order and plays it, stopping when you run out of files.
mpg321 -z --list artemis.txt
In big shuffle mode, mpg321 plays a random file and then plays another random file. mpg321 will go on until you stop it. This is great for jukebox style play, and when you just want a soundtrack to whatever else you are doing.
mpg321 -Z *
Further uses
Because mpg321 follows all the normal bash conventions, it is very easy to use in simple bash scripts, the only limit is your imagination. If you think of a novel use, then please do let us now in a comment below.
Links



1 Lou Gogan says...
Hi
Enjoy learning from your pages. There seems to be problems with the css <code> formatting - some of the text goes on and on - on the one line rather than wrapping. There also seems to be a problem with the line height of the css <code> formatting. Am using Firefox on Ubuntu Linux.
Thought I'd let you know.
Keep up the good work !
Lou Gogan
Posted at 6:27 p.m. on April 22, 2008
2 http://andry.mine.nu says...
To create play list better use:
# find /mnt/music/??????/ -name *.mp3 >> /home/andry/playlist.txt
it will add files to playlist recursive from ?????? folder.
Posted at 2:51 a.m. on October 8, 2008