I'm looking for the easiest way to play a MP3 file in C. I am looking for either a library, in which I could just call the function on the filename, or an executable that will just run and quit. Please suggest.
All you have to do is double-click on the MP3 file you want to listen to and by default, your audio player will open the file and start playing. If, however, you prefer a different audio player than either of those, changing the association of a file is a simple process on either Windows or macOS.
Using FMOD (cross platform), this should be as simple as this:
#include <conio.h> #include "inc/fmod.h" FSOUND_SAMPLE* handle; int main () { // init FMOD sound system FSOUND_Init (44100, 32, 0); // load and play mp3 handle=FSOUND_Sample_Load (0,"my.mp3",0, 0, 0); FSOUND_PlaySound (0,handle); // wait until the users hits a key to end the app while (!_kbhit()) { } // clean up FSOUND_Sample_Free (handle); FSOUND_Close(); }
As a side note, I'd suggest you using C++ over C.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With