cocos2d-x 音乐播放猜想

时间:2023-03-09 18:10:51
cocos2d-x 音乐播放猜想
"SimpleAudioEngine.cpp":
void SimpleAudioEngine::playBackgroundMusic(const char* pszFilePath, bool bLoop)
{
    if (! pszFilePath)
    {
        return;
    }

    sharedMusic().Open(_FullPath(pszFilePath).c_str(), _Hash(pszFilePath));
    sharedMusic().Play((bLoop) ? -1 : 1);
}
"MicPlayer.cpp":
void MciPlayer::Play(UINT uTimes /* = 1 */)
{
    if (! _dev)
    {
        return;
    }
    MCI_PLAY_PARMS mciPlay = {0};
    mciPlay.dwCallback = reinterpret_cast<DWORD_PTR>(_wnd);
    s_mciError = mciSendCommand(_dev,MCI_PLAY, MCI_FROM|MCI_NOTIFY,reinterpret_cast<DWORD_PTR>(&mciPlay));
    if (! s_mciError)
    {
        _playing = true;
        _times = uTimes;
    }
}
本文精华

在今天以前, 我一直以为这种技术含量高的音乐播放都是可以同步播放多种音乐.一直到今天看了cocos2d-x3.0源码才知道, 其实是单首音乐播放, 手工控制轮流播放实现同时播放的错觉.不过仔细想想, 即使我之前所想的高技术含量的音乐播放也都是采用轮询播放的方式, 只不过底层封装了而已.