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

System Message: WARNING/2 (<string>, line 3); backlink

Inline emphasis start-string without end-string.

it will add files to playlist recursive from ?????? folder.

Posted at 2:51 a.m. on October 8, 2008


What do you have to say?

Show Editing Help

About

Hello, my name is Zeth, I'll be your host here.

Command Line Warriors is about taking control of your own technology, it looks at our experiences of computing; especially using GNU/Linux, the Python programming language, the command-line and issues such as techno-ethics, best practices and whatever is cool now. If you take control of your technology then you are a Warrior too!

This site is your site too which means that you can contribute and get involved. You can leave comments using the facility provided. For me, the comments and discussions are by far the best part of the site. So please do have your say!

Latest Discussions

Cupcake

July 31, 2010
Good post! You helped me a lot with my school project! CountryField(blank = True) < (K)
Countries in Django

LeshaShampoo

July 30, 2010
it was very interesting to read commandline.org.uk I want to quote your post in my blog. It can? And you et an account on Twitter?
Email Syntax Check in Python

vemma2018

July 30, 2010
I find myself coming to your blog more and more often to the point where my visits are almost daily now!
On Comment Spam

layecenda

July 30, 2010
Hello. And Bye.test :) http://idfjhvihdfiphvlajbvhalibv.com
PuTTY Series: Adding PuTTY to your system path

scuba

July 30, 2010
I’ve been visiting your blog for a while now and I always find a gem in your new posts. Thanks for sharing.
On Comment Spam

Businesking

July 30, 2010
Great site and articles for hack for win, I said Amazing post
How not to program WSGI

Tehnoking

July 30, 2010
This is Great post to learn about the hack Thumbs-up for you :D
How not to program WSGI

Syabiltech

July 30, 2010
I think this articles for master...because very hard to learning, As blogger beginners like me.
How not to program WSGI

coffeeatea

July 30, 2010
Are you looking for coffee gifts? We can tell you more about the coffee gifts including coffee machines and coffee pods.
Introducing Soturi - yet another Django blog application

noni juice

July 30, 2010
I just sent this post to a bunch of my friends as I agree with most of what you’re saying here and the way you’ve presented it is awesome.
On Comment Spam

Dion Moult

July 29, 2010
What I do know is that ever since I tried out Opera and put their tab bar on the left as a column, I've loved that layout. Back on Firefox ...
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

ZonaEntertainment

July 29, 2010
Wow useful articles, I'm read to learn about this and now I bookmark this to my Facebook, thanks for share!
How not to program WSGI

Giacomo

July 29, 2010
Honestly, I think both Mozilla and you are wrong :) This sort of concept adds overhead. A user would have to manage all this crap, constantly dragging and dropping, creating ...
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

Matija "hook" Šuklje

July 29, 2010
As a minimalist, you'll probybly moan if I mention KDE, but I'll do so anyway ;) The future I want (and actually see slowly fold out before me) is to ...
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

tahitian noni

July 28, 2010
Thank You For This Blog, was added to my bookmarks.
On Comment Spam

Rick

July 28, 2010
I already have piles. It's called A New Window.
We need a thoughout integration of the desktop and the web - not Tab Candy superfast jellyfish

Tech News

July 25, 2010
Thanks for this short tutorial...was auto-FTPing my files from my appserver to webserver for my tech news website. Everything was OK until someone hacked it. Hosting provider is now recommending ...
SFTP in Python: Really Simple SSH

naypalm

July 24, 2010
During the past 3-4 years, I and many others have enjoyed unlimited 2G/3G internet. But ever since the massive cult-like following of i Phone users in the US, most cellular ...
Calling time on mobile internet nonsense?

Steve

July 15, 2010
Very occasionally, you will run into a Java program that uses a lot of memory just to hold all the classes used. It turns out that the JVM uses a ...
Three classic command line tips

no

July 14, 2010
1. number one 2. number two 4. number four 3. number three 6. number six # first # second ## second-ay ## second-bee ### second-bee-one ### second-bee-two
An Introduction to ReStructuredText