| 503 | } |
| 504 | |
| 505 | AudioCache* AudioEngineImpl::preload(std::string_view filePath, std::function<void(bool)> callback) |
| 506 | { |
| 507 | AudioCache* audioCache = nullptr; |
| 508 | |
| 509 | auto it = _audioCaches.find(filePath); |
| 510 | if (it == _audioCaches.end()) |
| 511 | { |
| 512 | audioCache = new AudioCache(); // hlookup_second(it); |
| 513 | _audioCaches.emplace(filePath, std::unique_ptr<AudioCache>(audioCache)); |
| 514 | audioCache->_fileFullPath = FileUtils::getInstance()->fullPathForFilename(filePath); |
| 515 | unsigned int cacheId = audioCache->_id; |
| 516 | auto isCacheDestroyed = audioCache->_isDestroyed; |
| 517 | AudioEngine::addTask([audioCache, cacheId, isCacheDestroyed]() { |
| 518 | if (*isCacheDestroyed) |
| 519 | { |
| 520 | AXLOGV("AudioCache (id={}) was destroyed, no need to launch readDataTask.", cacheId); |
| 521 | audioCache->setSkipReadDataTask(true); |
| 522 | return; |
| 523 | } |
| 524 | audioCache->readDataTask(cacheId); |
| 525 | }); |
| 526 | } |
| 527 | else |
| 528 | { |
| 529 | audioCache = it->second.get(); |
| 530 | } |
| 531 | |
| 532 | if (audioCache && callback) |
| 533 | { |
| 534 | audioCache->addLoadCallback(callback); |
| 535 | } |
| 536 | return audioCache; |
| 537 | } |
| 538 | |
| 539 | AUDIO_ID AudioEngineImpl::play2d(std::string_view filePath, bool loop, float volume, float time) |
| 540 | { |
nothing calls this directly
no test coverage detected