Listen to the radio at the Linux terminal

MPlayer is an extremely versatile open source media player that can be surprisingly useful at the Linux command line.
220 readers like this.
Linux toy: mplayer

Jason Baker

You've found your way to our 24-day-long Linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself what a command-line toy even is. It could be a game or any simple diversion that helps you have fun at the terminal.

Some of you will have seen various selections from our calendar before, but we hope there’s at least one new thing for everyone.

There are many ways to listen to music at the command line; if you've got media stored locally, cmus is a great option, but there are plenty of others as well.

Lots of times when I'm at the terminal, though, I'd really rather just zone out and not pay close attention to picking each song, and let someone else do the work. While I've got plenty of playlists that work for just such a purpose, after a while, even though go stale, and I'll switch over to an internet radio station.

Today's toy, MPlayer, is a versatile multimedia player that will support just about any media format you throw at it. If MPlayer is not already installed, you can probably find it packaged for your distribution. On Fedora, I found it in RPM Fusion (be aware that this is not an "official" repository for Fedora, so exercise caution):

$ sudo dnf install mplayer

MPlayer has a slew of command-line options to set depending on your situation. I wanted to listen to the local college radio station here in Raleigh (88.1 WKNC, they're pretty good!), and so after grabbing the streaming URL from their website, all that took to get my radio up and running, no GUI or web player needed, was:

$ mplayer -nocache -afm ffmpeg

MPlayer is open source under the GPLv3, and you can find out more about the project and download source code from the project's website.

As I mentioned in yesterday's article, I'm trying to use a screenshot of each toy as the lead image for each article, but as we moved into the world of audio, I had to fudge it a little. So today's image was created from a public domain icon of a radio tower using img2txt, which is provided by the libcaca package.

Do you have a favorite command-line toy that you we should have included? Our calendar is basically set for the remainder of the series, but we'd still love to feature some cool command-line toys in the new year. Let me know in the comments below, and I'll check it out. And let me know what you thought of today's amusement.

Be sure to check out yesterday's toy, Let you Linux terminal speak its mind, and come back tomorrow for another!

What to read next
User profile image.
Jason was an staff member and Red Hatter from 2013 to 2022. This profile contains his work-related articles from that time. Other contributions can be found on his personal account.


Seems I had mplayer already installed. Tried the command-line sample and it worked flawlessly! I never would have discovered this on my own. Can you explain the options used?


I looked at the basic help and then tried the man page for mplayer... it was overwhelming. Thanks!

Sure. Honestly, MPlayer is one of those tools that's complex enough that, once I get the winning combination of options going, I don't touch them, even if one is perhaps superfluous. :)

-nocache turns off caching. Caching could actually be useful, depending on your situation, but one thing I use internet radio streams of local stations a good bit for is basketball coverage, which I want synced with my TV at least reasonably well so I can get audio that's in time with the game (think of it as a Dick Vitale avoidance strategy). But do what works for you.

-afm directs which audio codec to use. I set this to ffmpeg because I've had the best luck with it working with a broad set of filetypes / encoding types. Depending on what kind of stream you're consuming, different songs could actually be encoded in different ways, and ffmpeg seems to be able to handle everything that my preferred stations throw at it. But again, your situation may vary: all I can say is, works for me!

In reply to by Jake (not verified)

Thanks for the reply. Explain shell is awesome!

> a good bit for is basketball coverage, which I want synced with my TV

I used to do the same (back in the analog days) when I watched baseball championship games. Some of the longstanding network announcers just didn't quite "have it" so I would replace them with local radio guys who were more focused on the game.

In reply to by Jason B

Great article! I second your shout-out for WKNC. I enjoy listening to them too!

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.