From 934b10d890ec403cd538936de25abb30c834ce93 Mon Sep 17 00:00:00 2001 From: Crylia Date: Tue, 26 Mar 2024 19:51:35 +0100 Subject: [PATCH] add sdl to cmake via package find --- CMakeLists.txt | 2 ++ src/core/audio/audio.cpp | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 03a3086..462d6b0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavutil ) PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) +find_package(SDL2 REQUIRED CONFIG) file(GLOB_RECURSE PROJECT_SOURCES src/*.cpp) file(GLOB_RECURSE PROJECT_HEADERS src/*.h) @@ -47,6 +48,7 @@ target_link_libraries(CryliaPlayer PRIVATE ${SDL_IMAGE_LIBRARY} ${SDL_MIXER_LIBRARY} PkgConfig::LIBAV + ${SDL2} ) install(TARGETS CryliaPlayer diff --git a/src/core/audio/audio.cpp b/src/core/audio/audio.cpp index d95646c..55c49d4 100644 --- a/src/core/audio/audio.cpp +++ b/src/core/audio/audio.cpp @@ -31,6 +31,9 @@ void Audio::StopMusic( ) { } void Audio::PlaySong(const std::string path) { + if (music) + Mix_FreeMusic(music); + this->path = path; music = Mix_LoadMUS(path.c_str( )); @@ -55,7 +58,7 @@ void Audio::ResumeMusic( ) { } bool Audio::IsMusicPlaying( ) { - return Mix_PlayingMusic( ); + return (Mix_PlayingMusic( ) != 0); } std::string Audio::GetTitle( ) {