C++., Simple line to play an MP3 File ("C:/MyFile.MP3)

Posted on 2011-04-22
Last Modified: 2012-06-21
Any simple programing command to simply play an MP3 file from my HardDrive in C++?

Please note that any depended external components have to be made clear and installed manually in my OS because I am using a bare, streamlined version of Windows XP.

Question by:New_Alex
    LVL 86

    Expert Comment

    The easiest solution would probably be to

    Open in new window

    LVL 7

    Expert Comment

    Shellexecute will open your mp3 in the default player program you have configured.
    If you want to run your mp3 in a particulay program then you need to try out their SDK.
    For example,
    For  VLC:
    System("c:\\path_to_VLC\\vlc.exe \"c:\\path\\file.mp3\"");

    For windows media player:
    System("c:\\path_to_wmplayer\\wmplayer.exe \"c:\\path\\file.mp3\"");
    LVL 1

    Author Comment

    Yes, but I want a method that will not depend on other players or anything I can not sell myself. If you know any media .exe or SDK etc that I can use in a commercial program then ok.

    Any Ideas?
    LVL 8

    Accepted Solution


    provides library to play back mp3 files plus command line player.

    with little tweaks (need zlib as well and some modifications here and there), I had madplay up and running in 10 minutes using Win SDK 7.1 + MSVC Express 2008 --
    300k exe, monolithic, no external dependencies at all --
    it should be trivial to look into madplay code, grab the main routine, link the whole thing into your own exe.
    LVL 8

    Expert Comment

    > ... that I can use in a commercial program ...

    oooops, missed that. libmad is GPL'ed...
    LVL 8

    Expert Comment

    Ooops again --
    from README file:

      This means MAD can be incorporated into other software as long as that
      software is also distributed under the GPL. (Should this be undesirable,
      alternate arrangements may be possible by contacting Underbit.)

    so commercial use is permitted too, as long as you get an agreement with the authors --
    LVL 1

    Author Comment

    I love you mate. Best answer ever !!!

    Full points are given man.

    Take care with my full wished.

    I thank all of you here for your response, I love you all...

    Happy Eastern,

    (Fuck Royal Family, turn your TV OFF during wedding ceremonies. )

    LVL 1

    Author Closing Comment

    Full points Deserved for this wonderful answer......
    I was looking for this long before....
    LVL 1

    Author Comment

    One more question if you don't mind. Is it possible to build this in Visual Studio C++ 2010?
    LVL 1

    Author Comment

    Hi Lomo. Can you tell me the steps you ve taken to manage to compile MadPlay in this thread?
    I will give you other full points if you do so...

    LVL 8

    Expert Comment

    mmmh VS 2010, I don't know...
    I did install it some time ago, but suddenly removed it as soon as I realized it wouldn't let me "attach to process" to debug... and since I occasionally write services, I really need this, so I went back to VS 2008.
    I suppose that it is possible, though, and steps needed for VS 2008 should be valid for VS 2010 too.
    So... instructions follow.

    1) download zlib, libmad, libid3tag, madplay from the internet:

    2) unpack zlib somewhere, let's say C:\work\zlib-1.2.5
    then go under that directory, open file win32\Makefile.msc
    change line 25 so it reads
    CFLAGS  = -nologo -MT -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
    instead of
    CFLAGS  = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)
    this is to statically link against CRT, thus removing dependencies from MSVCRwhatever.DLL. save, exit.
    now, open a SDK command prompt (so you have INCLUDE and LIB environment variables set correctly)
    cd C:\work\zlib-1.2.5
    type the command:
    nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" OBJA="match686.obj inffas32.obj"
    zlib is being built...

    3) ok so it's time to build mad...
    unpack the three mad projects somewhere, let's say C:\work\mad\...
    so now you have
    go to C:\work\mad\madplay-0.15.2b\msvc++, open file madplay.dsw with visual studio.
    confirm conversion of projects to the new format; it will complain about not finding zlib, ignore the error, we're going to provide our own.
    go to visual studio options / projects and solutions / VC++ directories; add C:\work\zlib-1.2.5 under include files and library files.
    build libid3tag.
    build libmad.
    then open properties of madplay project; under linker / input / dependencies add zlib.lib. do this for each configuration (debug, release).
    then build madplay. that's all...
    I hope I forgot nothing... if you find any problems let me know.
    Ciao - Lorenzo -

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now