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
The Ncurses interface will open in the Terminal, and the mp3 file will start playing. You can even monitor it in the progress bar.
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
The Ncurses window will open, showing your whole 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:
From the image below, cvlc is simple and lacks many exiting features.
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.
To play an mp3 file using mpg123, execute the command below:
$ mpg123 music-file.mp3
To play all mp3 files in a directory, navigate to that particular directory using the Terminal and run the command below:
Alternatively, you can shuffle your playlist with the -Z option. See the command below:
mpg123 -Z *.mp3
To view the entire list of all options, you can use with mpg123 utility, use the –longhelp command as shown below:
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;
Your music will start playing, but you will see a GUI window pop-up display the spectrum analyzer.
If you don’t wish to have the spectrum analyzer window, include the -nodisp option in your command.
ffplay -nodisp music-file.mp3
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.
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
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:
If you have a directory full of mp3 files, you can play them with the *.mp3 command.
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
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
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:
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:
To play all the mp3 files in a directory, run the command below;
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.