40 lines
1.1 KiB
C++
40 lines
1.1 KiB
C++
#include <Nazara/Audio.hpp>
|
|
#include <Nazara/Core.hpp>
|
|
#include <Nazara/Platform.hpp>
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
std::filesystem::path resourceDir = "assets";
|
|
if (!std::filesystem::is_directory(resourceDir) && std::filesystem::is_directory("../.." / resourceDir))
|
|
resourceDir = "../.." / resourceDir;
|
|
|
|
Nz::Application<Nz::Audio> app(argc, argv);
|
|
|
|
auto& windowing = app.AddComponent<Nz::WindowingAppComponent>();
|
|
auto& fs = app.AddComponent<Nz::FilesystemAppComponent>();
|
|
fs.Mount("game:/", resourceDir);
|
|
|
|
auto& catalog = app.AddComponent<Nz::AssetCatalogAppComponent>();
|
|
catalog.AddFolder("game:/");
|
|
|
|
// Load an asset from its path
|
|
Nz::Asset<Nz::Music> music = Nz::Asset<Nz::Music>::LoadFromFile("game:/examples/Audio/file_example_MP3_700KB.nzasset");
|
|
|
|
// or by its name
|
|
music = catalog.Load<Nz::Music>("file_example_MP3_700KB");
|
|
music->Play();
|
|
|
|
Nz::Asset<Nz::Sound> sound = catalog.Load<Nz::Sound>("examples/Audio/siren");
|
|
sound->Play();
|
|
|
|
app.AddUpdaterFunc([&]
|
|
{
|
|
if (!music->IsPlaying())
|
|
app.Quit();
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
});
|
|
|
|
return app.Run();
|
|
}
|