diff --git a/include/Nazara/Audio/Music.hpp b/include/Nazara/Audio/Music.hpp index 5a7955e0d..a86d96496 100644 --- a/include/Nazara/Audio/Music.hpp +++ b/include/Nazara/Audio/Music.hpp @@ -25,6 +25,8 @@ namespace Nz class NAZARA_AUDIO_API Music final : public Resource, public SoundEmitter { public: + using Params = SoundStreamParams; + Music(); Music(AudioDevice& device); Music(const Music&) = delete; @@ -46,9 +48,9 @@ namespace Nz bool IsLooping() const override; - bool OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params = SoundStreamParams()); - bool OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params = SoundStreamParams()); - bool OpenFromStream(Stream& stream, const SoundStreamParams& params = SoundStreamParams()); + static std::shared_ptr OpenFromFile(const std::filesystem::path& filePath, const Params& params = Params()); + static std::shared_ptr OpenFromMemory(const void* data, std::size_t size, const Params& params = Params()); + static std::shared_ptr OpenFromStream(Stream& stream, const Params& params = Params()); void Pause() override; void Play() override; diff --git a/src/Nazara/Audio/Music.cpp b/src/Nazara/Audio/Music.cpp index b296b07e9..9458af623 100644 --- a/src/Nazara/Audio/Music.cpp +++ b/src/Nazara/Audio/Music.cpp @@ -240,12 +240,17 @@ namespace Nz * \param filePath Path to the file * \param params Parameters for the music */ - bool Music::OpenFromFile(const std::filesystem::path& filePath, const SoundStreamParams& params) + std::shared_ptr Music::OpenFromFile(const std::filesystem::path& filePath, const Params& params) { + std::shared_ptr music = std::make_shared(); if (std::shared_ptr soundStream = SoundStream::OpenFromFile(filePath, params)) - return Create(std::move(soundStream)); - else - return false; + { + std::shared_ptr music = std::make_shared(); + if (music->Create(std::move(soundStream))) + return music; + } + + return {}; } /*! @@ -258,12 +263,16 @@ namespace Nz * * \remark The memory pointer must stay valid (accessible) as long as the music is playing */ - bool Music::OpenFromMemory(const void* data, std::size_t size, const SoundStreamParams& params) + std::shared_ptr Music::OpenFromMemory(const void* data, std::size_t size, const Params& params) { if (std::shared_ptr soundStream = SoundStream::OpenFromMemory(data, size, params)) - return Create(std::move(soundStream)); - else - return false; + { + std::shared_ptr music = std::make_shared(); + if (music->Create(std::move(soundStream))) + return music; + } + + return {}; } /*! @@ -275,12 +284,16 @@ namespace Nz * * \remark The stream must stay valid as long as the music is playing */ - bool Music::OpenFromStream(Stream& stream, const SoundStreamParams& params) + std::shared_ptr Music::OpenFromStream(Stream& stream, const Params& params) { if (std::shared_ptr soundStream = SoundStream::OpenFromStream(stream, params)) - return Create(std::move(soundStream)); - else - return false; + { + std::shared_ptr music = std::make_shared(); + if (music->Create(std::move(soundStream))) + return music; + } + + return {}; } /*! @@ -439,7 +452,7 @@ namespace Nz break; // We have reached the end of the stream, there is no use to add new buffers } } - catch (const std::exception&) + catch (const std::exception& e) { err = std::current_exception();