How to Play or Open *.Mp3 or *.Wav Sound File in C++ Program

How to play a sound in C++?

Ycao,

As far as I know, you will need some third party library.
Personally, I would use FMOD.
It's quite simple to use, well documented, you will find a lot code snippet to bootstart your project and it has a lot of interesting features.

FMOD Website

Is there a way to pause/stop a mp3 file playing with mcisendstring with the wait option?

You can use the wait/stop commands if the play command will be modified to avoid waiting until the *.mp3 has finished playing.

mciSendString("play mp3", NULL, 0, NULL);

Including winmm.lib does not work

If you read the compiler output carefully, you will see this warning:

warning: ignoring #pragma comment [-Wunknown-pragmas]

That means your compiler (GCC) does not support your code's use of #pragma comment, and so winmm.lib ends up not getting linked into your final executable, thus causing the subsequent linker error:

undefined reference to `_imp__mciSendStringA@16'

This is not a matter of the linker not being able to find winmm.lib, it is a matter of the linker not being told to use winmm.lib in the first place.

#pragma is used to invoke compiler-specific commands. Not all compilers implement #pragma comment. VC++ does (and so do a few others, like BCC32/64), but GCC does not. The other question you linked to was tagged visual-c++, so #pragma comment was appropriate in that case.

In your case, you will have to adjust your build process accordingly to use another way to tell the linker to use winmm.lib. You do that in GCC by using the -l option when invoking the linker, eg -lwinmm.

C++/Win32 - What in my MCI utilization is causing a delay?

I was talking to a friend, and he recommended that I use a thread. "Well, duh", I thought. "How could I possibly have not thought of that?"



Related Topics



Leave a reply



Submit