Skip to content

Commit

Permalink
修复音频播放无效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HalcyonAlcedo committed May 27, 2021
1 parent a775b78 commit 41e5ad7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
14 changes: 7 additions & 7 deletions Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LuaScript.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions deps/Sound/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 41e5ad7

Please sign in to comment.