cocos2dx windows下开发真是波折多多啊;最近又遇到了音量设置无效问题。
下面整理下方案,方便将来回忆
1,找到工程中libAudio工程,(如果没有,请加上,具体方法百度)
里面打开MciPlayer.h文件,
2,MciPlayer.h 中添加
#include <Digitalv.h>
如下
@H_403_22@public: void Volume(UINT volume) { if (!_dev) return; MCI_DGV_SETAUdio_PARMS mciParams = { 0 }; mciParams.dwItem = MCI_DGV_SETAUdio_VOLUME; mciParams.dwValue = volume; mciSendCommand(_dev,MCI_SETAUdio,MCI_DGV_SETAUdio_ITEM | MCI_DGV_SETAUdio_VALUE,(DWORD)&mciParams); } UINT MciPlayer::Volume() const { if (!_dev) return 0; MCI_STATUS_PARMS mciParams = { 0 }; mciParams.dwItem = MCI_DGV_STATUS_VOLUME; mciSendCommand(_dev,MCI_STATUS,MCI_STATUS_ITEM,(DWORD)&mciParams); return mciParams.dwReturn; }3,依然libAudio工程中打开SimpleAudioEngine.cpp文件
float SimpleAudioEngine::getBackgroundMusicVolume() { //return 1.0; // add by xxj 2014/11/06 15:34:19 return sharedMusic().Volume() / 1000.0f; } void SimpleAudioEngine::setBackgroundMusicVolume(float volume) { // add by xxj 2014/11/06 15:58:13 sharedMusic().Volume((UINT)(volume * 1000.0)); } float SimpleAudioEngine::getEffectsVolume() { //return 1.0; // add by xxj 2014/11/06 15:34:41 return sharedList().begin()->second->Volume() / 1000.0f; } void SimpleAudioEngine::setEffectsVolume(float volume) { // add by xxj 2014/11/06 15:58:07 EffectList::iterator iter; for (iter = sharedList().begin(); iter != sharedList().end(); iter++) { iter->second->Volume((UINT)(volume * 1000.0)); } }
ok,大功告成
注意:设置音量之前先要播放哦!!
参考链接:http://blog.csdn.net/u012855000/article/details/20841943
原文链接:/cocos2dx/346342.html