The easiest way to play mp3 with Visual C ++

A few years ago, I wrote some utility library around DShow / DSound to allow me to play MP3s in a Windows C ++ application. Is this a normal way to do this in a C ++ / MFC application, or is it a DirectX area that has been included in the common Windows APIs?

The motivation is that we just use the standard Windows PlaySound method for WAV and would like to be able to play MP3 files using a similar simple API provided by Windows or something we write to wrap more complex functions.

EDIT: This is for a large commercial open source project. And we just want to just play, there won't be a lot to pay for the library.

+6
winapi audio mp3 mci directshow
source share
6 answers

You can use DirectShow, but it is no longer part of DirectX, or rely on a third-party library like Bass , FMod , mpg123, or even libwmp3 .

If you no longer want to use DirectShow (but why change if your existing code continues to work?), You can use MCI :

mciSendString("open la_chenille.mp3 type mpegvideo alias song1", NULL, 0, 0); mciSendString("play song1", NULL, 0, 0); mciSendString("close song1", NULL, 0, 0); 
+6
source share

This is an easy way to play any audio file: http://msdn.microsoft.com/en-us/library/dd390090(VS.85).aspx

+3
source share

You can use the functions of the MCI windows, https://msdn.microsoft.com/en-us/library/ms709626

It can play many audio file formats, including MP3, WAV, MIDI, etc.

If I remember correctly, it does not require DirectX.

PlaySound may also work for you.

+2
source share

If you do not want to pay a license and want to do it yourself, parse your mp3 file and transfer it to XAudio2. This is something you can do once (2-3 hours maximum) and always use .: P

0
source share

PlaySound () natively supports MP3 as long as it is embedded in the WAV file. People do not understand that WAV is a container format. Download the ffmpeg utilities to convert the header and save the codec:

ffmpeg -i input.mp3 -c copy -f wav embedded_mp3.wav

0
source share

You can watch the BASS . It is an easy-to-use audio library, free for non-commercial use.

-one
source share

All Articles