mirror of https://github.com/axmolengine/axmol.git
AudioEngine:support preload for audio[MAC/iOS]
This commit is contained in:
parent
b395ef06d8
commit
5d50663c35
|
@ -61,7 +61,7 @@ public:
|
||||||
|
|
||||||
void uncache(const std::string& filePath);
|
void uncache(const std::string& filePath);
|
||||||
void uncacheAll();
|
void uncacheAll();
|
||||||
|
AudioCache* preload(const std::string& filePath);
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -283,6 +283,24 @@ bool AudioEngineImpl::init()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudioCache* AudioEngineImpl::preload(const std::string& filePath)
|
||||||
|
{
|
||||||
|
AudioCache* audioCache = nullptr;
|
||||||
|
|
||||||
|
auto it = _audioCaches.find(filePath);
|
||||||
|
if (it == _audioCaches.end()) {
|
||||||
|
audioCache = &_audioCaches[filePath];
|
||||||
|
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
||||||
|
|
||||||
|
_threadPool->addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
audioCache = &it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return audioCache;
|
||||||
|
}
|
||||||
|
|
||||||
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume)
|
||||||
{
|
{
|
||||||
if (s_ALDevice == nullptr) {
|
if (s_ALDevice == nullptr) {
|
||||||
|
@ -303,16 +321,9 @@ int AudioEngineImpl::play2d(const std::string &filePath ,bool loop ,float volume
|
||||||
return AudioEngine::INVALID_AUDIO_ID;
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioCache* audioCache = nullptr;
|
AudioCache* audioCache = preload(filePath);
|
||||||
auto it = _audioCaches.find(filePath);
|
if (audioCache == nullptr) {
|
||||||
if (it == _audioCaches.end()) {
|
return AudioEngine::INVALID_AUDIO_ID;
|
||||||
audioCache = &_audioCaches[filePath];
|
|
||||||
audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
|
||||||
|
|
||||||
_threadPool->addTask(std::bind(&AudioCache::readDataTask, audioCache));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
audioCache = &it->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto player = &_audioPlayers[_currentAudioID];
|
auto player = &_audioPlayers[_currentAudioID];
|
||||||
|
|
Loading…
Reference in New Issue