Cocos2d-X 使用OpenSL ES播放音效的并发限制(Too many objects) iOS Android

Cool.Cat 2015-11-28 2891

OpenSL ES是支持多线且线程安全的(SL_ENGINEOPTION_THREADSAFE),但是每个应用程序支持最大只支持创建32个音效对象(Objects),因此最好在业务层对同一时刻播放音效的次数做出限制,否则在CreateAudioPlayer时会得到Too many objects的错误,并返回错误(SL_RESULT_MEMORY_FAILURE)


OpenSL ES for Android is designed for multi-threaded applications, and is thread-safe. OpenSL ES for Android supports a single engine per application, and up to 32 objects. Available device memory and CPU may further restrict the usable number of objects.
slCreateEngine recognizes, but ignores, these engine options:
SL_ENGINEOPTION_THREADSAFE SL_ENGINEOPTION_LOSSOFCONTROL OpenMAX AL and OpenSL ES may be used together in the same application. In this case, there is internally a single shared engine object, and the 32 object limit is shared between OpenMAX AL and OpenSL ES. The application should first create both engines, then use both engines, and finally destroy both engines. The implementation maintains a reference count on the shared engine, so that it is correctly destroyed at the second destroy.


另外由于OpenSL ES使用了全局的共享资源,因此当项目切换后台或不工作时记得要销毁AudioPlayer


Be sure to destroy your audio players when your activity is paused, as they are a global resource shared with other apps.


具体详情可参阅:OpenSL ES Doc

最新回复 (0)
返回
发新帖
X