| 68 | } |
| 69 | |
| 70 | void AudioCache::loadAsync(String filename, const std::function<void(AudioFile*)>& handler) { |
| 71 | std::string fullPath = SharedContent.getFullPath(filename); |
| 72 | std::string file(filename.toString()); |
| 73 | SharedContent.loadAsyncUnsafe(fullPath, [this, file, fullPath, handler](uint8_t* data, int64_t size) { |
| 74 | auto fileSize = s_cast<size_t>(size); |
| 75 | AudioFile* audioFile = nullptr; |
| 76 | if (shouldStream(fullPath, fileSize)) { |
| 77 | audioFile = WavStream::create(MakeOwnArray(data), fileSize); |
| 78 | } else { |
| 79 | audioFile = WavFile::create(MakeOwnArray(data), fileSize); |
| 80 | } |
| 81 | if (audioFile) { |
| 82 | _audioFiles[fullPath] = audioFile; |
| 83 | handler(audioFile); |
| 84 | } else { |
| 85 | Error("failed to load sound file \"{}\".", file); |
| 86 | handler(nullptr); |
| 87 | } |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | bool AudioCache::unload(AudioFile* audioFile) { |
| 92 | for (const auto& it : _audioFiles) { |
nothing calls this directly
no test coverage detected