fixed a bug in AudioPlayer.cpp, thank oz01.

This commit is contained in:
hyzboy 2024-02-24 00:10:34 +08:00
parent 1f3ff2ecea
commit 6e5334bd3e
No known key found for this signature in database
GPG Key ID: 067EE4525D4FB6D3

View File

@ -72,6 +72,8 @@ namespace hgl
AudioPlayer::~AudioPlayer() AudioPlayer::~AudioPlayer()
{ {
SAFE_CLEAR(decode);
if(!audio_data)return; if(!audio_data)return;
Clear(); Clear();
@ -87,11 +89,19 @@ namespace hgl
if(!plugin_name)return(false); if(!plugin_name)return(false);
AudioPlugInInterface decode; decode=new AudioPlugInInterface;
if(GetAudioInterface(plugin_name,&decode,nullptr)) if (!GetAudioInterface(plugin_name, decode, nullptr))
{ {
audio_ptr=decode.Open(audio_data,audio_data_size,&format,&rate,&total_time); delete decode;
decode=nullptr;
LOG_ERROR(OS_TEXT("无法加载音频解码插件:")+OSString(plugin_name));
return(false);
}
{
audio_ptr=decode->Open(audio_data,audio_data_size,&format,&rate,&total_time);
audio_buffer_size=(AudioTime(format,rate)+9)/10; // 1/10 秒 audio_buffer_size=(AudioTime(format,rate)+9)/10; // 1/10 秒
@ -107,7 +117,6 @@ namespace hgl
return(true); return(true);
} }
else return(false);
} }
/** /**
@ -242,6 +251,8 @@ namespace hgl
bool AudioPlayer::ReadData(ALuint n) bool AudioPlayer::ReadData(ALuint n)
{ {
if(!decode)return(false);
uint size; uint size;
size=decode->Read(audio_ptr,audio_buffer,audio_buffer_size); size=decode->Read(audio_ptr,audio_buffer,audio_buffer_size);
@ -261,6 +272,7 @@ namespace hgl
bool AudioPlayer::Playback() bool AudioPlayer::Playback()
{ {
if(!audio_data)return(false); if(!audio_data)return(false);
if(!decode)return(false);
alSourceStop(source); alSourceStop(source);
ClearBuffer(); ClearBuffer();