The function of preloadeffect function in playing cocos2d-x audio in Android

Source: Internet
Author: User

Link: http://blog.csdn.net/zhangxaochen/article/details/8010634

I have never known the functions of the preloadeffect function, but I guess it may increase the startup efficiency of the program. As a result, we ran into the use case o (cost □cost) O today.

Here: http://is.gd/VoBVUJ

The story is like this...

Compiled a applet to Android, in which the sound will be played during the touch screen. However, when the program is running, the first touch screen always has no sound effects. At that time, it was suggested that the loading of audio files would be delayed, so the screen would be updated after the startup, but the second problem still exists. I don't know how to add a root rib to my head. I suddenly thought of the preloadeffect function. Just try it. So we first pre-loaded the audio file, which eliminates the "second problem "!

My experiments prove that this problem will occur if preloadeffect is not used in cocos2dx 1.0-XX or later versions 2.0.2.

========================================================== ==========

Personal thinking:

1. The existence is reasonable. Since a function such as preloadeffect exists, it must be used to solve a problem. Previously, I always thought this function was a chicken fault, because on Win32, even if there was no preload, I never encountered the "second problem ".

2. Read the source code of preload:

void SimpleAudioEngine::preloadEffect(const char* pszFilePath){    int nRet = 0;    do     {        BREAK_IF(! pszFilePath);        nRet = _Hash(pszFilePath);        BREAK_IF(sharedList().end() != sharedList().find(nRet));        sharedList().insert(Effect(nRet, new MciPlayer()));        MciPlayer * pPlayer = sharedList()[nRet];        pPlayer->Open(_FullPath(pszFilePath), nRet);        BREAK_IF(nRet == pPlayer->GetSoundID());        sharedList().erase(nRet);        nRet = 0;    } while (0);}

The general process is to assign a number to the file to be played. If the number is not in the sharedlist (), add it to the sharedlist audio effect list.

However, I still think the "second problem" is like a bug, because logically, even if we do not have a preload, even if you are delayed for the first time, at least let me know. It's strange to say nothing for the first time...

 

Finally, there is another problem to be solved, that is, no matter how high the volume of my mobile phone is (for example, it is set to mute or to the maximum volume), the sound volume remains unchanged, it seems that there are no associated buttons in the engine .. I don't understand. Help ~

 

Link: http://blog.csdn.net/zhangxaochen/article/details/8010634
{Over }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.