MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / playSoundEntry

Method playSoundEntry

apps/tools/Studio/StudioApp.cpp:188–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188void 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
239static std::string StripPboExtension(const std::string& path)
240{

Callers

nothing calls this directly

Calls 12

logFunction · 0.85
isVirtualMethod · 0.80
playMemoryMethod · 0.80
durationMethod · 0.80
StripPboExtensionFunction · 0.70
RStringClass · 0.50
openMethod · 0.45
LockMethod · 0.45
errorMethod · 0.45
ReadMethod · 0.45
GetSizeMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected