-
How do I play an MP3?
Hey, I was looking at MSDEV's help thing to see how to "play multimedia", trying to figure out how I could play an MP3 file from my program... the only thing that looked promising was "PlaySound", so I tried it. (by the way, does that play mp3's?) But when I tried compiling, it said there was an "unresolved external symbol _imp__PlaySoundA@12". Am I missing a header or something? (or should i use something else to play an mp3?)
-
I think you would need a special decoding routine.
Probably better just to use the system, if you assume that your program's user has Winamp or something else with MP3 capability.
-
you can use different libraries to play sounds:
when i made a media player i used fmod: < www.fmod.org >
and, it looks like you are missing a library ( look on MSDN to see what libraries u need to include )
-
Thanks.
But when I looked on MSDN (that's the CD thing right?) it just said "use PlaySound." and gave the syntax.
-
-
Forget PlaySound - I never got it to work with MP3s.
Use the API command mciSendCommand to open and play the MP3 file. mciSendCommand is documented in the MSDN, however, it doesn't refer to MP3s explicitly.
However, if you call mciSendCommand with the MCI_ALL_DEVICE_ID device type - it will play.
Example:
[code]
MCI_OPEN_PARMS op;
op.dwCallback = NULL;
op.lpstrDeviceType = (char*)MCI_ALL_DEVICE_ID;
op.lpstrElementName = "you_file_name.mp3";
op.lpstrAlias = NULL;
// Open command
mciSendCommand( NULL, MCI_OPEN,
MCI_OPEN_ELEMENT | MCI_WAIT | MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID, (DWORD)&op);
// Play command
MCI_PLAY_PARMS pp;
pp.dwCallback = NULL;
pp.dwFrom = 0;
mciSendCommand(pDevice, MCI_PLAY, MCI_NOTIFY | MCI_FROM, (DWORD)&pp);
[\code]
-
>> [\code]
The proper ending tag is [/code]
-
An other possibility is to use directx. but the downside to it is that you need the Directx SDK. I've made a class for playing an mp3. But it isn't fully tested. And with finals comming up I don't have the time to perfect them. I'll attach the zip file so you can use them if you want to. choice is yours.
But I must say. I'm no expert in classes. It is possible that this isn't the world best class :D
-
You need to include the winmm library for PlaySound() to work.
I had a hard time finding that too =)
just add -lwinmm (yes there should be an l there) to your compiler commands
-
>> [\code]
The proper ending tag is [/code]
[code]
Well Excyuuuuuuse me
[\code]
-
-
>> [code]
>> Well Excyuuuuuuse me
>> [\code]
LMAO :D
-
lol davros, nice try with the code blocks :D But thanks anyways, i'll try the mciSendCommand thingee out.
-
oh, umm... just wondering, what's pDevice? I was wondering because of 2 reasons: (a)I couldnt figure that out, and (b)the compiler couldnt either, and it wont compile (surprise surprise!).
-
My apologies:
pDevice is a private variable from my own code (which I used to construct my earlier reply).
The MCI device handle is returned by the MCI_OPEN command in the MCI_OPEN_PARAMS structure. All other commands to an open device must specify this handle.