From 41e5ad75be903b8074052b0fec006bfb218fa795 Mon Sep 17 00:00:00 2001 From: HalcyonAlcedo Date: Thu, 27 May 2021 16:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9F=B3=E9=A2=91=E6=92=AD?= =?UTF-8?q?=E6=94=BE=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Base.h | 14 +++++++------- LuaScript.h | 2 +- deps/Sound/Player.cpp | 1 + 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Base.h b/Base.h index 7e80d1c..fbc8f8b 100644 --- a/Base.h +++ b/Base.h @@ -380,13 +380,13 @@ namespace Base { //ÒôƵ²¥·Å #pragma region SoundPlay namespace SoundPlay { - static void PlaySound(string SoundFile) { - Sound sound; - Player player; - if (!player.Create()) return; - if (!sound.LoadFromFile(SoundFile)) return; - if (!player.SetSound(sound)) return; - player.Play(); + static void PlaySoundFile(string SoundFile) { + Player* player = new Player(); + Sound* sound = new Sound(); + player->Create(); + sound->LoadFromFile(SoundFile); + player->SetSound(*sound); + player->Play(); } } #pragma endregion diff --git a/LuaScript.h b/LuaScript.h index ffb7b06..5eeb6bd 100644 --- a/LuaScript.h +++ b/LuaScript.h @@ -1274,7 +1274,7 @@ static int System_UI_RemoveText(lua_State* pL) { } static int System_Sound_PlaySound(lua_State* pL) { string file = (string)lua_tostring(pL, 1); - Base::SoundPlay::PlaySound(file); + Base::SoundPlay::PlaySoundFile(file); return 0; } diff --git a/deps/Sound/Player.cpp b/deps/Sound/Player.cpp index 227ea81..daf76e0 100644 --- a/deps/Sound/Player.cpp +++ b/deps/Sound/Player.cpp @@ -57,6 +57,7 @@ bool Player::SetSound(Sound& sound) bool Player::Play() { + if (AudioSVoice == nullptr) return false; if (FAILED(AudioSVoice->Start())) return false; std::thread t(&Player::PlayBuffer, this); play_thread.swap(t);