Thread: How do I play an MP3?

  1. #1
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879

    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?)
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    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.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    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 )
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Thanks.

    But when I looked on MSDN (that's the CD thing right?) it just said "use PlaySound." and gave the syntax.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Try searching for PlaySound at http://msdn.microsoft.com/library/default.asp
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  6. #6
    Davros
    Guest
    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]

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >> [\code]
    The proper ending tag is [/code]
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  8. #8
    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

  9. #9
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    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

  10. #10
    Davros
    Guest
    >> [\code]
    The proper ending tag is [/code]

    [code]
    Well Excyuuuuuuse me
    [\code]

  11. #11
    Davros
    Guest
    Code:
    Doooh!

  12. #12
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >> [code]
    >> Well Excyuuuuuuse me
    >> [\code]

    LMAO
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  13. #13
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    lol davros, nice try with the code blocks But thanks anyways, i'll try the mciSendCommand thingee out.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  14. #14
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    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!).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  15. #15
    Davros
    Guest
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. play MP3 on win32 consol project
    By Skull in forum C++ Programming
    Replies: 11
    Last Post: 02-09-2008, 04:30 PM
  2. not able to play MP3 files in SUSE 10.0
    By kris.c in forum Tech Board
    Replies: 0
    Last Post: 09-14-2006, 04:36 AM
  3. Mp3 play - MCI
    By geek@02 in forum Windows Programming
    Replies: 4
    Last Post: 09-30-2004, 08:07 PM
  4. Gui Class With Tic Tac Toe
    By xxYukoxx in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2003, 04:28 PM
  5. Play Mp3...
    By Jperensky in forum C++ Programming
    Replies: 3
    Last Post: 04-26-2003, 02:08 PM