| 186 | } |
| 187 | |
| 188 | void StudioApp::playSoundEntry(const FileEntry& entry) |
| 189 | { |
| 190 | if (entry.isVirtual()) |
| 191 | { |
| 192 | try |
| 193 | { |
| 194 | QFBank bank; |
| 195 | std::string bankName = StripPboExtension(entry.pboPath); |
| 196 | if (!bank.open(RString(bankName.c_str()))) |
| 197 | { |
| 198 | log("Audio: Failed to open PBO: " + entry.pboPath); |
| 199 | return; |
| 200 | } |
| 201 | bank.Lock(); |
| 202 | if (bank.error()) |
| 203 | { |
| 204 | log("Audio: PBO load error: " + entry.pboPath); |
| 205 | return; |
| 206 | } |
| 207 | Ref<IFileBuffer> data = bank.Read(entry.pboFilename.c_str()); |
| 208 | if (!data || data->GetSize() == 0) |
| 209 | { |
| 210 | log("Audio: Failed to read from PBO: " + entry.pboFilename); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | stopSound(); |
| 215 | if (!soundPlayer) |
| 216 | soundPlayer = std::make_unique<SoundPlayer>(); |
| 217 | |
| 218 | if (!soundPlayer->playMemory(data->GetData(), data->GetSize(), entry.extension.c_str())) |
| 219 | { |
| 220 | log("Audio: Cannot load: " + entry.pboFilename); |
| 221 | return; |
| 222 | } |
| 223 | soundPlaying = true; |
| 224 | soundStartTime = std::chrono::steady_clock::now(); |
| 225 | soundPlayingFile = entry.pboFilename; |
| 226 | log("Playing: " + entry.pboFilename + " (" + std::to_string(soundPlayer->duration()) + "s)"); |
| 227 | } |
| 228 | catch (const std::exception& e) |
| 229 | { |
| 230 | log("Audio: " + std::string(e.what())); |
| 231 | } |
| 232 | } |
| 233 | else |
| 234 | { |
| 235 | playSoundFile(entry.fullPath); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | static std::string StripPboExtension(const std::string& path) |
| 240 | { |
nothing calls this directly
no test coverage detected