tags:

views:

5748

answers:

8

Hello all,

I'm looking for the easiet way to play an MP3 file in C. Either a library I could use and just call the function on the filename, or alternatively something someone's already written that will just run and quit.

Thanks! Let me know if I can be any more clear.

+2  A: 

I don't know if it is "the easiest way", but you could have a look at SDL (along with SDL_sound).

Guishu
+1  A: 

If you are on Windows or OSX, I recommend BASS (http://www.un4seen.com/bass.html)

You can download the library and look at code sample to get started. The "contest" example in C directory is a good start point.

m3rLinEz
+3  A: 

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.

friol
+1  A: 

If u can use C++ and if u are working on windows platform than use WMp3

That Library is easy to work with and let you play, pause, seek on mp3 files.

Lav
A: 

alternatively something someone's already written that will just run and quit.

You can use mpg123 (or the fixed point port of it, mpg321)

mpg123 <mp3file>

will play an mp3 file and quit.

codelogic
+1  A: 

On Win32, you don't need any library. Use standard Win32 api (mp3 is native)

See on Adv. Win32 api newsgroup : news://comp.os.ms-windows.programmer.win32 where it 's a FAQ.

http://www.codeproject.com/KB/audio-video/MP3Example.aspx
bobobobo
+1  A: 

The BASS DLL is really easy to use and will probably do what you need. It is only free for non-commercial use though.

If you need more control, you will need a codec (I prefer libMad) and some sound output API like DirectSound on Windows or ALSA or Linux (or whatever Linux guys use for sound this week)

DrJokepu
A: 

mpg123 has a generic remote interface that you access by starting the executable with the -R option. You can then send commands (such as load, pause etc) over a fifo pipe or to stdin of the subprocess. If nothing else it's easy to debug and test manually.

Hank