Cocos在Win32平台调试时 无法播放.ogg格式的音乐的解决办法
Cocos在Win32平台调试时 无法播放.ogg格式的音乐的解决办法
下载一个解码器
下载安装 K-Lite Mega Codec Pack 建议装9.0以上的版本。
更改Cocos2d-x源码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| 路径:cocos\audio\win32\MciPlayer.cpp: void MciPlayer::Open(const char* pFileName, UINT uId) { do { BREAK_IF(! pFileName || ! _wnd); int nLen = (int)strlen(pFileName); BREAK_IF(! nLen); int nBufLen = MultiByteToWideChar(CP_UTF8, 0, pFileName, nLen + 1, nullptr, 0); LPWSTR pBuf = new WCHAR[nBufLen]; BREAK_IF(! pBuf); MultiByteToWideChar(CP_UTF8, 0, pFileName, nLen + 1, pBuf, nBufLen);
Close();
MCI_OPEN_PARMSW mciOpen = {0}; MCIERROR mciError; mciOpen.lpstrDeviceType = TEXT("MPEGVideo"); mciOpen.lpstrElementName = pFileName;
mciError = mciSendCommandW(0,MCI_OPEN, MCI_OPEN_ELEMENT | MCI_OPEN_TYPE, reinterpret_cast<DWORD_PTR>(&mciOpen)); BREAK_IF(mciError);
_dev = mciOpen.wDeviceID; _soundID = uId; _playing = false; } while (0); }
|
修改的地方1
mciOpen.lpstrDeviceType = TEXT(“MPEGVideo”);
修改的地方2
mciError = mciSendCommandW(0,MCI_OPEN, MCI_OPEN_ELEMENT | MCI_OPEN_TYPE, reinterpret_cast(&mciOpen));