visual MP3播放使用mci发送字符串c++
visual MP3 playing using mci send string c++
我想在我做的一个项目中播放一些mp3文件作为我的背景音乐。我试着用mcisendstring播放它,但它就是不能工作:(
这些是我所做的:
CMP3_MCI myMp3;
std::string address= "C:\Users\music embed testing\test.mp3";
myMp3.Load(address);
myMp3.Play();
//加载函数void Load(string szFileName)
{
m_szFileName = szFileName;
Load2();
}
//load2函数void Load2()
{
std::string szCommand = "open "" + GetFileName() + "" type mpegvideo alias " + GetFileName();
mciSendString(szCommand.c_str(), NULL, 0, 0);
}
//播放功能void Play()
{
std::string szCommand = "play " + GetFileName() + " from 0";
mciSendString(szCommand.c_str(), NULL, 0, 0);
}
//getFileName基本上返回m_szFileName作为私有属性存储
经过反复试验,我终于找到了一种使它工作的方法。对于那些和我面临同样问题的人,我想说:
//if you are using unicode
LPCWSTR a = L"open cannon.mp3 type mpegvideo";
int error = 99;
error = mciSendString(a, NULL,0,0);
int error2;
LPCWSTR b = L"play cannon.mp3";
error2 = mciSendString(b, NULL, 0, 0);
//cannon.mp3 is stored in my resource file
//error is just for debugging
//if you are using multibyte
LPCSTR a = "open cannon.mp3 type mpegvideo";
mciSendString(a, NULL, 0,0);
LPCSTR b = "play cannon.mp3 repeat";
int error2 = mciSendString(b, NULL, 0, 0);