How to play MP3 files in C?

前端 未结 10 1444
遇见更好的自我
遇见更好的自我 2020-12-01 01:15

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 w

相关标签:
10条回答
  • 2020-12-01 01:18

    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.

    0 讨论(0)
  • 2020-12-01 01:25

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

    0 讨论(0)
  • 2020-12-01 01:25

    Go here:

    http://code4k.blogspot.com/2010/05/playing-mp3-in-c-using-plain-windows.html

    This website has a zip in which you can view how this person generated the code for an mp3 player.

    You can also check out: http://www.codeguru.com/cpp/g-m/directx/directshow/article.php/c19079/Simple-C-MP3-Player-Class.htm

    or

    http://www.ucancode.net/Visual_C_Control/Play-MP3-File-VC-Sample-Player.htm

    0 讨论(0)
  • 2020-12-01 01:26

    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.

    0 讨论(0)
  • 2020-12-01 01:30

    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.

    0 讨论(0)
  • 2020-12-01 01:30

    Basically you can use the windows.h header file

    #include <windows.h>
    void main()
    {
        //replace music with your filename
        system("start music.mp3");
    }
    
    0 讨论(0)
提交回复
热议问题