Windows function for mp3 files?

This is a discussion on Windows function for mp3 files? within the Windows Programming forums, part of the Platform Specific Boards category; I'm writing a program a lot like an alarm clock. But PlaySound() only plays .wav files which can be freaking ...

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    Windows function for mp3 files?

    I'm writing a program a lot like an alarm clock. But PlaySound() only plays .wav files which can be freaking massive in size. Nobody wants .wav files these days. I want mp3 capability baby!

    I heard something about fmod, some thing I have to download. Is this what I need? Are there other options? Thanks.

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    As far as I know there is no standard Windows function to play MP3. But there are a lot of MP3 decoders, for example take a look at http://www.thefreecountry.com/ then take the section to audio libraries.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    3
    There is not likely to be a function like this since getting licensing rights to decode MP3s costs about $60,000. I suggest you instead use ShellExecute() to open the file that you wish to be played and this will cause whatever MP3s are associated with on your system (Windows Media Player, WinAmp...) to open and play the song.

  4. #4
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    I have found Windows WILL play MP3s, but it is not documented. What decoder it uses, I don't know, but it seems to work on all installations of Windows I've tried.

    You need to use the MCI interface and open an MP3 as 'all device types', like so:

    Code:
      MCI_OPEN_PARMS op; // <- data structure
      op.dwCallback = NULL;
      op.lpstrDeviceType = (char*)MCI_ALL_DEVICE_ID; // <- integer value cast as char*
      op.lpstrElementName = fName.c_str(); // <-filename string
      op.lpstrAlias = NULL;
    
      // Send command to
      mciSendCommand( NULL, MCI_OPEN,  MCI_OPEN_ELEMENT | MCI_WAIT, (DWORD)&op) );
    Check out the MS documentation for MCI and mciSendCommand.

    Personally, if you want your alarm clock to play a 'ping' or short sound, I would stick with wavs & PlaySound.

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,255
    Actually I believe MP3, MPEG video and most others go through a common MCI interface. If you specify an MCI device type as "MPEGVideo", modern (Win95B+) systems open up a can of quartz.dll. This in turn links to DirectX Media, so if you have filters for that file format (i.e. It'll play in Media Player), it'll play it.

    I doubt that code snippet would work on a pre-Win98 system...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  5. Dos commands hehe
    By Carp in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-17-2003, 01:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21