Playing an mp3 file using MCI
-
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);
} -
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);
}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<
-
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);
}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)[^]