In this article/video we will see a code with OOP on how to play MP3 with C++, there are other libraries that also do this, some others only play WAV, for example, the gamedev libraries.
First of all we need to know which libraries we need to know the differences between: Mpg123, LibMPG123 and Libao:
It is a free and open source audio player. Supports MPEG audio formats, including MP3. It is an application that works via command line and does not have a graphical interface.
It is the library developed and used by the Mpg123 application. It is also the same one used in applications: Audacious, XMMS and Winamp.
It is a cross-platform audio library that allows programs to produce audio using a simple API across a wide variety of platforms.
It is a tool developed by Xiph.Org, the same one that created the file type:
ogg and also the
FLAC format, which is a free alternative to
mp3 and other formats.
Watch the video
Code created in the video
Create a project
Add the files with the codes below:
Compiling and playing an MP3
Use the song you want as an example, download the song.
Music: SAINt JHN - “Trap” ft. Lil Baby (Music available at https://en.mygomp3.com/):
wget -q https://cutt.ly/musicmp3 -O music.mp3.