How to make ubuntu play mp3 files
Because of licensing issues, Ubuntu is unable to play MP3s out of the box. We’ll show you how to play MP3s and other restricted file formats in about four mouse clicks.
The philosophy behind Ubuntu is that software should be free and accessible to all. Whether MP3 and other file formats are free is unclear in many countries, so Ubuntu does not include software to read these file formats by default.
Fortunately, it does include a package that installs the most commonly used file formats all at once, including a Flash plugin for Firefox.
Note: These instructions are for Ubuntu 10.04. There are small differences for earlier versions of Ubuntu.
Play MP3 Files
Open the Ubuntu Software Center, found in the Applications menu.
Click on View and ensure that All Software is selected.
Type “restricted extras” into the search box at the top-right. Find the Ubuntu restricted extras package and click Install.
Enter your password when prompted.
Once the install is complete, close out of Ubuntu Software Center, and you’ll be able to play MP3 files! To confirm this, we’ll open up Rhythmbox, found in the Sound & Video section of the Applications menu.
Our test MP3 plays with no problems!
Note: If Rhythmbox tells you that MP3 plugins are not installed, close Rhythmbox and reopen it. You should not have to install anything extra through Rhythmbox.
Despite this extra step, playing the most common audio and video file formats – including Flash videos on the internet – is simple. All the software comes installed, you just have to teach them how to read your files.
I have installed Ubuntu 11.10 server.. so command line only.
I need to be able to play audio (.mp3 & .wav) files via the command line!
I’ve installed the MPD & Audacious packages. and copied some files to a location specified in the .conf file.
But what do I do to acutally play the .mp3 files??
Also, how can I confirm the AUDIO is working correctly?
/music/thisfolder/thisorthat.mp3″ – deleted Jul 3 ’13 at 22:12
11 Answers 11
For wav you can use aplay . For mp3 you can use mpg123 .
If you already have ffmpeg installed (you should have ffmpeg installed default with ubuntu), try:
I usually just do mplayer foo.mp3 to play audio from the command line.
The play command from the sox package will play any file format supported by sox
To install sox open terminal and run:
To use play command:
Use man sox for more information
Not sure if your server will support it, but VLC also has a command line version that can play (with the right packages) MP3 files:
The ‘n’ in front of ‘vlc’ invokes the ncurses interface which is for the command line. This allows you to play multiple files, pause and control the files being played.
And additionally you can use nvlc –random /path/to/your/music/folder to play random songs from a Music folder.
Or use cvlc instead of nvlc , for even minimal interaction.
If you have shifted towards Ubuntu from Windows OS, it will seem hard to use that Linux based OS especially the command line. Because most of the Linux functionalities based on the command line. Even most Linux users prefer to run Linux server distributions that entirely depend on the Terminal with no graphical desktop because that offers higher stability, speed, and less utilization of resources.
In the start, it will be a little harder for you to get friendly with the Ubuntu desktop or Server edition. Still, you can enjoy the enjoy music and videos in Ubuntu without having any advanced knowledge of Ubuntu GUI or command line.
So today, we are going to have a look at some ways using GUI and Terminal to play mp3 files in Ubuntu. I am using Ubuntu 18.04 LTS for running commands and explaining the methods.
Play MP3 using default audio player Rhythmbox
It is the default player in Ubuntu for playing mp3 and other formats including WAV, OGG, FLAC, etc.
To launch Rhythmbox application, Press Windows key or Click on dash icon in the bottom left corner of the desktop to open the dash menu. Then search for Rhythmbox application by typing its name in the search bar. When the application appears, click on it to open it.
When the application opens, you will need to import the mp3 files. Click on the + icon to add files.
Then click on Load from File.
If you have a playlist, you can upload that. Otherwise, select All Files options from the bottom, then choose the path in your computer where the mp3 files are located. Then click on Open.
Once the file is opened, click on the Play button to play the mp3 file.
There is an alternative way to play mp3 files using Rhythmbox. To use that, navigate to the folder where the mp3 files are located. Select the mp3 file, right-click on it, and then select Properties.
In the Properties window, click on the OpenWith tab.
From the recommended applications, select the Rhythmbox to set as a default application. Now whenever you will open any mp3 file, it will automatically open in Rhythmbox application.
Play MP3 with mpg123 app
Mpg123 lets you play any mp3 files from the Terminal. To install it using the Terminal, press Ctrl+Alt+T. It will launch the Terminal. Then enter the following command:
When prompted to continue, press y from the keyboard.
Navigate to the folder containing mp3 files. Type cd followed by the directory where the mp3 files are located. I have my mp3 files contained in Ubuntu’s Downloads folder.
The general syntax of the command is:
Then type mpg123 followed by the mp3 filename:
Mpg123 supports wildcard so that you can send several mp3 files at once. Type the above same command but replace the file name with *.mp3 like below:
Using VLC Player to play MP3 Music Files
In Ubuntu, you can also use the popular VLC player used mostly by Windows user. To install VLC player, open the Terminal by pressing Ctrl+Alt+T key combination.
Then enter the below command in Terminal:
To start VLC player, use the following command in the Terminal window:
It will launch the VLC player. Click on Media from the top menu bar. Then from the drop-down list, select Open File.
In the window that appears, choose the mp3 file that you want to play and click on Open.
It will instantly play the mp3 file in VLC player.
So these were the three ways using which you can play mp3 files that include built-in application Rhythmbox, command line application mpg123, and open source VLC program. You can also use various other freeware programs for playing mp3 files in Ubuntu.
- ← How to Install VMware Tools in Ubuntu 18.04 LTS
- How to Create an ISO File in Ubuntu 18.04 LTS →
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.
I am looking for a way to normalize the sound in MANY MP3 files I have. Some have low sound, while others are louder so I have to turn the volume up or down depending on the song. What ways are there to do this for all files. I specially would like to do it via the terminal but GUI ways are also accepted.
9 Answers 9
Audacity
With Audacity we can easily batch process files to apply conversions or effects to many files in a list. To do so we first have to define a “Chain” containing the effects we want to apply.
This is done with “File –> Edit Chains. “. In the now opening window press the Add button on the bottom left to insert a new chain (give it a sensible name):
Then choose the effect and it’s parameters to insert to the chain (here shown for default values and the Normalize effect).
Important: we always need to also add the effect “Export MP3” (or any other export format) for saving the resulting conversion to disk.
When done leave this window with OK to open “File –> Apply Chain. “. Select the Chain we have just created and load all files you need with “Apply to files. “. Several files can be selected from the file chooser that opens.
Processed files will be saved in a new subdirectory “cleaned” in the original’s path.
From version > 14.3 we can use the sox filter –norm for normalizing audio on the command line or for batch processing:
MP3-support is added to Sox with libsox-fmt-all:
Take a look @ mp3gain which for me is even better than normalize-audio
another useful version could be the -c which prevent to ask if you want to do the changes for many files:
as said in the man page:
mp3gain does not just do peak normalization, as many normalizers do. Instead, it does some statistical analysis to determine how loud the file actually sounds to the human ear. Also, the changes mp3gain makes are completely lossless. There is no quality lost in the change because the program adjusts the mp3 file directly, without decoding and re-encoding.
Note: That package was removed on purpose on ubuntu 15.04.
Debian proposes the python-rgain package as replacement (The advantage is that ‘replaygain’ supports several file formats, namely Ogg Vorbis , Flac, WavPack and MP3. Also, it allows you to view existing Replay Gain information in any of those file types). After installing it, run replaygain .
To install python-rgain from the terminal, run the command
Alternatively, get the .deb file for 14.04 (the latest) from here. Install as usual. After that, you need to run sudo apt-get -f install to correct some dependencies issues.
I would use this project Normalize, it’s a command-line tool for normalizing audio files. Looks to be exactly what you need. Can do batch processing and doesn’t require resampling to intermediate formats.
It’s in the package repos as normalize-audio, sudo apt-get install normalize-audio . This is a build maintained upstream by Debian so it should be in anything LTS or newer and is built with mp3 compatibility (tested). There is a good manpage man normalize-audio to explore the options but the commands defaults appear to work well. For batch processing (normalize volume across multiple files), normalize-audio -b *.mp3 or specify individual filenames instead of using wildcards.
2020 update: replaygain/rgain is currently not being developed, try rgain3, a modern fork. Here on pip.
Install: pip install rgain3 .
replaygain is faster and easier:
This package provides a Python package to calculate the Replay Gain values of audio files and normalize the volume of those files according to the values. Two basic scripts exploiting these capabilities are shipped as well.
Replay Gain is a proposed standard designed to solve the very problem of varying volumes across audio files.
Install: sudo apt install python-rgain .
- -f, –force Recalculate Replay Gain even if the file already contains gain information.
Since only calculate/change replaygain value, is also faster: With an average PC (Intel i7-6500U, 8GB RAM) the rate was
Reference
- ReplayGain article at Wikipedia
- python-rgain at Launchpad
For the sake of it, I’ll throw my 2 cents in. I was looking for exactly the same thing (only for ogg files) and started a thread at Crunchbang Forum. You can view it here: Normalize-audio can’t find mp3 decoder
Basically my solution was the script in post #8. It works for mp3, flac, and ogg input files, possibly others but definitely not wav.
Just create a file (name it whatever you want, I called mine db_adjust_mp3), chmod +x , and stick it in your
/bin folder. It fills in any missing codec data as well. Example:
Original file: 16._This_Protector.mp3: Audio file with ID3 version 2.3.0, contains:
Normalized file: 16._This_Protector.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo
I’ve modified the script to use normalize-mp3 here so you can use it if you want:
This script calculates the difference between the current db level and -12db, then applies a gain adjustment to put the gain at exactly -12db, which is what I’ve found works the best for me. It is recursive as well, which makes it great for doing entire music collections or files in many subfolders. If you wish to set a different db level, just change the both instances of the number “12” to whatever db level you would like to use. As I posted in my Crunchbang thread, usage is as follows:
However, when I used to keep my music library in mp3 format, I used to use mp3gain as well, just as Philippe suggested. The dead simplicity of it is great and I really liked it. The problem with normalize-audio though is that it does decode an re-endcode the files, so there is some sound degradation. But unless you’re an audiophile and your mp3’s are encoded at a high bitrate you shouldn’t notice much difference.
The thing I noticed with mp3gain though was that no matter what options I tried I couldn’t get everything in my collection to be exactly the same db level, which is what I want so that I never have to adjust the volume from one track to the next. This script does exactly that. Sorry for being so long winded. Hope this helps.
After Ubuntu 18 .04 LTS was released, I decided to install it for testing purposes… the steps below is how I got Ubuntu to play video files and other video formats… If you’re looking for a simple way to enable Ubuntu desktops to play videos, the steps below should be a great place to start…
By default Ubuntu Desktop will not play most videos files and some other media formats. Unless you install restricted decoders and codecs that are purposely left out, you won’t be able to watch movies, or videos you downloaded from YouTube.
These restrictions are in place for legal and technical reasons. Ubuntu excluded these codecs because these video files and other media formats are copy-right protected. You can’t just add these protected technology to your operating systems and programs without agreeing to their licensing terms and conditions.
In order to watch these videos, you need to have these codecs installed. A codec is a piece of software that allows applications to read a video or audio format. That’s why when you try to watch a video in Ubuntu you sometimes get an error that Ubuntu is unable to play the file.
This brief tutorial shows you how to install these restricted programs and codecs so you can begin watching movies and videos files on Ubuntu.
When you attempt to watch a video file formatted in MPEG-4 you’ll get the error message as shown below:
XXX-X AAC decoder, H.264 (Main Profile) decoder are required to play the file, but are not installed.
The reason you get the error is because your Ubuntu desktop is missing the required codecs or decoders. The video you’re trying to watch is using a copy-right protected technology and Ubuntu is not designed to play them.
You must install these packages below in order to play those videos. Run the commands below to install the missing codecs and decoders from Ubuntu Desktops.
After running the commands above, Ubuntu should immediately begin playing those videos that failed to play previously. This is how to get Ubuntu to play copy-right video files and other format.
If for some reasons the videos are still not playing, you may want to restart your computer and try again.
Last updated February 9, 2020 By Abhishek Prakash 51 Comments
If you have just installed Ubuntu or some other Ubuntu flavors like Kubuntu, Lubuntu etc, you’ll notice that your system doesn’t play some audio or video file.
For video files, you can install VLC on Ubuntu. VLC one of the best video players for Linux and can play almost any video file format. But you’ll still have troubles with audio media files and flash player.
The good thing is that Ubuntu provides a single package to install all the essential media codecs: ubuntu-restricted-extras.
What is Ubuntu Restricted Extras?
The ubuntu-restricted-extras is a software package that consists various essential software like flash plugin, unrar, gstreamer, mp4, codecs for Chromium browser in Ubuntu etc.
Since these software are not open source and some of them involve software patents, Ubuntu doesn’t install them by default. You’ll have to use multiverse repository, the software repository specifically created by Ubuntu to provide non-open source software to its users.
How to install Ubuntu Restricted Extras?
I find it surprising that the software center doesn’t list Ubuntu Restricted Extras. In any case, you can install the package using command line and it’s very simple.
Open a terminal by searching for it in the menu or using the terminal keyboard shortcut Ctrl+Alt+T.
Since ubuntu-restrcited-extras package is available in the multiverse repository, you should verify that the multiverse repository is enabled on your system:
And then you can install it in Ubuntu default edition using this command:
When you enter the command, you’ll be asked to enter your password. When you type the password, nothing is displayed on the screen. That’s normal. Type your password and press enter.
It will show a huge list of packages to be installed. Press enter to confirm your selection when it asks.
You’ll also encounter an EULA (End User License Agreement) screen like this:
It could be overwhelming to navigate this screen but don’t worry. Just press tab and it will highlight the options. When the correct options are highlighted, press enter to confirm your selection.
Once the process finishes, you should be able to play MP3 and other media formats thanks to newly installed media codecs.
Installing restricted extra package on Kubuntu, Lubuntu, Xubuntu
Do keep in mind that Kubuntu, Lubuntu and Xubuntu has this package available with their own respective names. They should have just used the same name but they don’t unfortunately.
On Kubuntu, use this command:
On Xubuntu, you should use:
I always recommend getting ubuntu-restricted-extras as one of the essential things to do after installing Ubuntu. It’s good to have a single command to install multiple codecs in Ubuntu.
I hope you like this quick tip in the Ubuntu beginner series. I’ll share more such tips in the future.
Like what you read? Please share it with others.
- Tips
- Blog
- Hvordan
- Vinduer
- Telefon
- Vigtigste
- Hvordan
- Sådan laver du Ubuntu Play MP3 Files
På grund af licensproblemer kan Ubuntu ikke afspille MP3’er ud af boksen. Vi viser dig, hvordan du afspiller MP3’er og andre begrænsede filformater i omkring fire museklik.
Filosofien bag Ubuntu er, at softwaren skal være fri og tilgængelig for alle. Uanset om MP3 og andre filformater er gratis, er det uklart i mange lande, så Ubuntu indeholder ikke software til at læse disse filformater som standard.
Heldigvis omfatter den en pakke, der installerer de mest almindeligt anvendte filformater på én gang, herunder et Flash-plugin til Firefox.
Bemærk: Disse instruktioner gælder for Ubuntu 10.04. Der er små forskelle for tidligere versioner af Ubuntu.
Afspil MP3-filer
Åbn Ubuntu Software Center, der findes i menuen Programmer.
Klik på Vis og sørg for at All software er valgt.
Skriv “begrænset ekstrafunktioner” i søgefeltet øverst til højre. Find Ubuntu begrænsede ekstramateriale pakke og klik på Installer.
Indtast dit kodeord, når du bliver bedt om det.
Når installationen er afsluttet, lukker du ud af Ubuntu Software Center, og du kan spille MP3-filer! For at bekræfte dette åbner vi Rhythmbox, der findes i afsnittet Lyd og video i menuen Programmer.
Vores test MP3 spiller uden problemer!
Bemærk: Hvis Rhythmbox fortæller dig at MP3-plugins ikke er installeret, skal du lukke Rhythmbox og genåbne den. Du skal ikke installere noget ekstra via Rhythmbox.
På trods af dette ekstra trin er det nemt at afspille de mest almindelige lyd- og videofilformater – herunder Flash-videoer på internettet. Alt softwaren kommer installeret, du skal bare lære dem at læse dine filer.
I would like to make an alarm system backed by a Ubuntu (no graphical interface) box, which plays various announcement and alarm audio tracks (.mp3 or .wav) via the command line.
The audio should come from the PC audio jack. I might also wrap it with another socket listener (for example, Ruby Sinatra).
How can I do this?
10 Answers 10
mpg123 is a command-line utility which plays mp3 files. You can install it in Ubuntu with:
The play command from the sox package will play any file format supported by sox using the default audio device, e.g
You may need to install extra packages to gain support for all formats, for example on Ubuntu 11.04 the MP3 support is not available until you install libsox-fmt-mp3 .
The most standard way to play a WAV file in Linux is using the aplay command, which is part of the ALSA system.
(Both in Fedora and in Ubuntu/Mint it is part of the alsa-utils package)
This does not require any additional packages to your Linux installation like sox or mplayer or vlc, just the basic ALSA which is a part of any system nowadays.
Install vlc by using:
Make sure that you have all repositories open. Also run the following before you install:
VLC has a command-line operation method invoked by cvlc . The next part would be to write a .sh that will call the command. I am no good at writing bash scripts. The end-result would be something like:
You can simply pipe your sound data to the pc speaker device:
On Ubuntu 16.04 (Xenial Xerus), there is no need to install anything. You can play a sound using paplay with is part of the PulseAudio sound server:
MPlayer is another player which can play pretty much any audio/video format from command line. To install it in Ubuntu just execute this command:
You can then play the file using this syntax:
I found another way:
FFmpeg is installed on my Ubuntu 19.04 (Disco Dingo)
canberra-gtk-play
For simple Bash scripts MPlayer is probably a bit too heavy and too verbose in terms of output. A built-in option is canberra-gtk-play which comes preinstalled on Ubuntu:
Note: it uses the alerts volume, and you must pass –file= in order to play a file from a path.
It can also play a sound by id which represents the file name without extension of media files under /usr/share/sounds (apparently this only works for sounds that are registered as part of a sound theme):
gst-launch-1.0/gst-launch-0.10
Another option is using the gstreamer command-line tools which are present on most modern Linux boxes:
To suppress all output redirect it to /dev/null :
Both gst-launch-1.0 and gst-launch-0.10 might be present on your system.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago .
I’m a student of Computer Science. I have a final semester Project to develop a short game in graphics along with the sound.
6 Answers 6
First of all, write the following code:
To play and wait until the *.mp3 has finished playing:
To replay (play again from start) the *.mp3:
To replay and wait until the *.mp3 has finished playing:
To play the *.mp3 and replay it every time it ends like a loop:
If you want to do something when the *.mp3 has finished playing, then you need to RegisterClassEx by the WNDCLASSEX structure, CreateWindowEx and process it’s messages with the GetMessage, TranslateMessage and DispatchMessage functions in a while loop and call:
In the window procedure, add the case MM_MCINOTIFY: The code in there will be executed when the mp3 has finished playing.
But if you program a Console Application and you don’t deal with windows, then you can CreateThread in suspend state by specifying the CREATE_SUSPENDED flag in the dwCreationFlags parameter and keep the return value in a static variable and call it whatever you want. For instance, I call it mp3. The type of this static variable is HANDLE of course.
Here is the ThreadProc for the lpStartAddress of this thread:
All what you have to do now is to ResumeThread(mp3); every time you want to replay your mp3 and something will happen every time it finishes.
You can #define play_my_mp3 ResumeThread(mp3); to make your code more readable.
Of course you can remove the while (true) , SuspendThread and the from 0 codes, if you want to play your mp3 file only once and do whatever you want when it is over.
If you only remove the SuspendThread call, then the sound will play over and over again and do something whenever it is over. This is equivalent to:
To pause the *.mp3 in middle:
and to resume it:
To stop it in middle:
Note that you cannot resume a sound that has been stopped, but only paused, but you can replay it by carrying out the play command. When you’re done playing this *.mp3, don’t forget to:
All these actions also apply to (work with) wave files too, but with wave files, you can use “waveaudio” instead of “mpegvideo”. Also you can just play them directly without opening them:
If you don’t want to specify an handle to a module:
If you don’t want to wait until the playback is over:
To play the wave file over and over again:
Note that you must specify both the SND_ASYNC and SND_LOOP flags, because you never going to wait until a sound, that repeats itself countless times, is over!
Also you can fopen the wave file and copy all it’s bytes to a buffer (an enormous/huge (very big) array of bytes) with the fread function and then:
Either OpenFile or CreateFile or CreateFile2 and either ReadFile or ReadFileEx functions can be used instead of fopen and fread functions.
Hope this fully answers perfectly your question.