Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Playing an mp3 file using MCI

Playing an mp3 file using MCI

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
3 Posts 2 Posters 5 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Derell Licht
    wrote on last edited by
    #1

    I am trying to play an mp3 file from a WinAPI/C++ application. I'm using 32-bit MinGW on Windows 10. I found an example program which uses the MCI (winmm) interface to play the file; I found an example command-line program which implements this using mciSendString() calls... I had some problems handling paths to the mp3 file, and *thought* I had fixed it by converting the paths to 8.3 short format... the command-line program plays the files just fine, but when I import exactly the same code into my WinAPI dialog-box application, although the MCI functions all return success, no sound plays... Does anyone have any idea what is missing here?? Or does this library just not work from a Windows dialog app? Here's the code:

      {
      static char short\_str\[MAX\_WAVE\_FILE\_LEN+1\] = "" ;
      CMP3\_MCI MyMP3;
      int result = GetShortPathName (wave\_name, short\_str, MAX\_WAVE\_FILE\_LEN);
      syslog("short: %d: \[%s\]\\n", result, short\_str);
      DWORD lerror = MyMP3.Load(short\_str);
      DWORD serror = MyMP3.Play();
      syslog("MCI: Load: %08X, Play: %08X\\n", lerror, serror);
      }
    

    And here are the load and play functions from his MCI class:

    inline MCIERROR Load()
    {
    std::string szCommand = "open \"" + GetFileName() + "\" type mpegvideo alias " + GetFileName();
    return mciSendString(szCommand.c_str(), NULL, 0, 0);
    }

    inline MCIERROR Load(char *szFileName)
    {
    m_szFileName = szFileName;
    return Load();
    }

    inline MCIERROR Play()
    {
    std::string szCommand = "play " + GetFileName() + " from 0";
    return mciSendString(szCommand.c_str(), NULL, 0, 0);
    }

    S D 2 Replies Last reply
    0
    • D Derell Licht

      I am trying to play an mp3 file from a WinAPI/C++ application. I'm using 32-bit MinGW on Windows 10. I found an example program which uses the MCI (winmm) interface to play the file; I found an example command-line program which implements this using mciSendString() calls... I had some problems handling paths to the mp3 file, and *thought* I had fixed it by converting the paths to 8.3 short format... the command-line program plays the files just fine, but when I import exactly the same code into my WinAPI dialog-box application, although the MCI functions all return success, no sound plays... Does anyone have any idea what is missing here?? Or does this library just not work from a Windows dialog app? Here's the code:

        {
        static char short\_str\[MAX\_WAVE\_FILE\_LEN+1\] = "" ;
        CMP3\_MCI MyMP3;
        int result = GetShortPathName (wave\_name, short\_str, MAX\_WAVE\_FILE\_LEN);
        syslog("short: %d: \[%s\]\\n", result, short\_str);
        DWORD lerror = MyMP3.Load(short\_str);
        DWORD serror = MyMP3.Play();
        syslog("MCI: Load: %08X, Play: %08X\\n", lerror, serror);
        }
      

      And here are the load and play functions from his MCI class:

      inline MCIERROR Load()
      {
      std::string szCommand = "open \"" + GetFileName() + "\" type mpegvideo alias " + GetFileName();
      return mciSendString(szCommand.c_str(), NULL, 0, 0);
      }

      inline MCIERROR Load(char *szFileName)
      {
      m_szFileName = szFileName;
      return Load();
      }

      inline MCIERROR Play()
      {
      std::string szCommand = "play " + GetFileName() + " from 0";
      return mciSendString(szCommand.c_str(), NULL, 0, 0);
      }

      S Offline
      S Offline
      Shao Voon Wong
      wrote on last edited by
      #2

      This is a [Simple C++ DirectShow MP3 Player Class](https://www.codeproject.com/Articles/373613/Simple-Cplusplus-DirectShow-MP-Player-Class) for native C++ and .NET. This is an example on how to use the Mp3 class. ```Cpp #include "Mp3.h" void main() { // Initialize COM ::CoInitialize(NULL); std::wcout<

      1 Reply Last reply
      0
      • D Derell Licht

        I am trying to play an mp3 file from a WinAPI/C++ application. I'm using 32-bit MinGW on Windows 10. I found an example program which uses the MCI (winmm) interface to play the file; I found an example command-line program which implements this using mciSendString() calls... I had some problems handling paths to the mp3 file, and *thought* I had fixed it by converting the paths to 8.3 short format... the command-line program plays the files just fine, but when I import exactly the same code into my WinAPI dialog-box application, although the MCI functions all return success, no sound plays... Does anyone have any idea what is missing here?? Or does this library just not work from a Windows dialog app? Here's the code:

          {
          static char short\_str\[MAX\_WAVE\_FILE\_LEN+1\] = "" ;
          CMP3\_MCI MyMP3;
          int result = GetShortPathName (wave\_name, short\_str, MAX\_WAVE\_FILE\_LEN);
          syslog("short: %d: \[%s\]\\n", result, short\_str);
          DWORD lerror = MyMP3.Load(short\_str);
          DWORD serror = MyMP3.Play();
          syslog("MCI: Load: %08X, Play: %08X\\n", lerror, serror);
          }
        

        And here are the load and play functions from his MCI class:

        inline MCIERROR Load()
        {
        std::string szCommand = "open \"" + GetFileName() + "\" type mpegvideo alias " + GetFileName();
        return mciSendString(szCommand.c_str(), NULL, 0, 0);
        }

        inline MCIERROR Load(char *szFileName)
        {
        m_szFileName = szFileName;
        return Load();
        }

        inline MCIERROR Play()
        {
        std::string szCommand = "play " + GetFileName() + " from 0";
        return mciSendString(szCommand.c_str(), NULL, 0, 0);
        }

        D Offline
        D Offline
        Derell Licht
        wrote on last edited by
        #3

        Well, all of the Windows-supported libraries present problems, especially if one is building using MinGW rather than Visual C++. Generally, they cannot be built at all without a massive amount of hacking the code bases to make them MinGW-compatible. No DirectShow apps will build, neither will the more-recent MS audio interface (don't recall the name at the moment). However, I found a freeware library called zplay, which is easy to build, open source, and nice, compact code... it also has the ability to play other formats, such as flac... so I'll just go with that... libZPlay multimedia library (Win32)[^]

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups