Home Terminal Tuts How to play MP3 by command line in Linux

How to play MP3 by command line in Linux

by Arun Kumar
Play MP3 music

The Linux Terminal is one of the most powerful and reliable utilities one can get hands-on. You can use it to install packages and applications, execute programs, solve arising system issues, etc. But what would be more captivating than being able to play your mp3 music from the Terminal? Other than refreshment, there are situations where the Terminal is all you have to perform your tasks.

In this post, we will show you the various ways you can use to play your music from the command-line in Linux.

Play MP3 music via Command-Line

To get started, we will need to use several tools, most of which don’t come pre-installed. However, this shouldn’t worry you as we will give a detailed guide on how to install them in various Linux distributions

VLC to play mp3 music in command-line

VLC is one of the best and most popular media players. It supports a wide range of video and audio formats, making it the right choice for this post. However, we will not use the VLC – GUI (Graphical User Interface); instead, we will use the nvlc tool, the Ncurses interface of the VLC application.

Installing VLC in Ubuntu:

sudo apt update
sudo apt install vlc

To play an mp3 file in the command-line, launch the Terminal and execute the command below:

$ nvlc <file-name>
e.g.;
$ nvlc music-file.mp3
nvlc utility

nvlc utility

The Ncurses interface will open in the Terminal, and the mp3 file will start playing. You can even monitor it in the progress bar.

nvlc Ncurses interface

nvlc Ncurses interface

Like the VLC-GUI player, nvlc also comes with several control buttons ensuring you have an excellent experience. You can use Spacebar to pause your music and Left/Right arrow keys to forward or rewind your music.

If you have a directory full of music, you can play the entire playlist with the command below:

$ nvlc <path-to-your-directory>
e.g.,
$ nvlc /home/tuts/Desktop/MUSIC
nvlc to play Playlist

nvlc to play a playlist

The Ncurses window will open, showing your whole playlist.

Playlist

Playlist

Another VLC utility you use to play your music in the command line is cvlc. However, unlike nlvc, cvlc is simple, less verbose, and doesn’t use the Ncurses interface. To play a song with cvlc, execute the command below:

cvlc music-file.mp3
cvlc

cvlc

From the image below, cvlc is simple and lacks many exiting features.

cvlc dummy interface

cvlc dummy interface

MPG123 to play mp3 music using the command-line

Another popular utility for playing mp3 music in the command-line is mpg123. Unlike VLC, mpg123 comes pre-installed in several distributions. However, if it is not available for you, follow the steps below:

Install mpg123 in Ubuntu:

$ sudo apt update
$ sudo apt -y install mpg123

Install mpg123 Fedora:

$ sudo dnf install snapd
$ sudo ln -s /var/lib/snapd/snap /snap
$ sudo ln -s /var/lib/snapd/snap /snap

mpg123 comes with a lot more options that you can use. Execute the command below to see all of them.

mpg123 --help
mpg123 help command

mpg123 help command

To play an mp3 file using mpg123, execute the command below:

$ mpg123 music-file.mp3
mpg123 play music

mpg123 play music

To play all mp3 files in a directory, navigate to that particular directory using the Terminal and run the command below:

mpg123 *.mp3
mpg123 playlist

mpg123 playlist

Alternatively, you can shuffle your playlist with the -Z option. See the command below:

mpg123 -Z *.mp3
mpg123 shuffle songs

mpg123 shuffle songs

To view the entire list of all options, you can use with mpg123 utility, use the –longhelp command as shown below:

mpg123 --longhelp

FFplay

FFplay is a built-in media player that comes with the FFmpeg media tools. FFmpeg is a powerful utility used not only to play media files but also to perform other numerous tasks. It doesn’t come pre-installed but is available for most Linux distributions.

Install FFmpeg on Ubuntu:

sudo apt update
sudo apt install ffmpeg

Install FFmpeg on Fedora:

sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf -y install https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
sudo dnf -y install ffmpeg
sudo dnf -y install ffmpeg-devel

To play your mp3 file in the command-line with ffplay, execute the command below;

ffplay music-file.mp3

Your music will start playing, but you will see a GUI window pop-up display the spectrum analyzer.

ffplay spectrum window

ffplay spectrum window

If you don’t wish to have the spectrum analyzer window, include the -nodisp option in your command.

ffplay -nodisp music-file.mp3
ffplay show nodisplay

ffplay nodisplay

Like any other Linux tool, the ffplay comes wit a set of options that you can use while playing your music. You can see these options with the –help command.

ffplay --help

For example, if you don’t want ffplay to display the build config and license information banner, use the -hide_banner argument.

ffplay -nodisp -hide_banner music-file.mp3
ffplay hide banner

ffplay hide banner

Mplayer to play mp3 music on the command-line

Mplayer is another excellent utility we can use to play mp3 files in the Terminal. Even though this tool doesn’t come pre-installed, it is available for most Linux distributions. It also supports several control functions like the Spacebar for pause/play, Left/Right arrow keys to forward or rewind your music.

Install mplayer on Ubuntu:

$ sudo add-apt-repository universe
$ sudo apt update
$ sudo apt install mplayer MPlayer-gui

Install Mplayer on Fedora:

$ sudo dnf -y install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
$ dnf install mplayer

To play an mp3 file in the background with Mplayer, execute the command below:

mplayer music-file.mp3
mplayer

MPlayer

If you have a directory full of mp3 files, you can play them with the *.mp3 command.

mplayer *.mp3
mplayer playlist

MPlayer playlist

If you are playing an extensive playlist, it would be nicer if you could shuffle through the list. Include the -shuffle flag in your command.

mplayer -shuffle *.mp3
mplayer shuffle

MPlayer shuffle

You can also repeat a single song as many times as you wish with the -loop argument. The command below will repeat that particular song 25 times.

mplayer -loop music-file.mp3
mplayer loop

MPlayer loop

Other essential options to use with the MPlayer are -gui and –nogui. Just like the name suggests, if you want to play a file with GUI, you will include the -gui parameter. If not, use -nogui.

mplayer -gui music-file.mp3
or;
mplayer -nogui music-file.mp3

Those are but a few options you can use with the MPlayer utility. To view all of them, execute the command below:

mplayer --help
mplayer --help

MPlayer –help

Sox to play mp3 files in the command-line

Another powerful utility you can use to play mp3 files on your Terminal is Sox. Other than playing media files, Sox can convert various media file formats, record audio, and apply sound effects. This tool is available for most major distributions.

Install Sox on Ubuntu:

sudo apt update
sudo apt install sox
sudo apt install libsox-fmt-all

To play mp3 music with Sox, execute the command below:

play music-file.mp3
Sox

Sox

To play all the mp3 files in a directory, run the command below;

play *.mp3
Sox Playlist

Sox Playlist

Conclusion

Those are some of the best tools you can use to play mp3 files in the command-line. My favorite is VLC since it supports many media formats and comes with an intuitive Ncurses command-line interface. However, that shouldn’t limit your decision. Pick the tool that you feel comfortable with and enjoy your music.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.