Merge branch 'fix-stop-audio' of https://github.com/Tryibion/FlaxEngine into Tryibion-fix-stop-audio

This commit is contained in:
Wojtek Figat
2024-08-15 15:14:25 +02:00
2 changed files with 23 additions and 0 deletions

View File

@@ -338,6 +338,7 @@ void AudioSource::PlayInternal()
AudioBackend::Source::Play(this); AudioBackend::Source::Play(this);
_isActuallyPlayingSth = true; _isActuallyPlayingSth = true;
_startingToPlay = true;
} }
#if USE_EDITOR #if USE_EDITOR
@@ -419,6 +420,27 @@ void AudioSource::Update()
AudioBackend::Source::VelocityChanged(this); AudioBackend::Source::VelocityChanged(this);
} }
// Reset starting to play value once time is greater than zero
if (_startingToPlay && GetTime() > 0.0f)
{
_startingToPlay = false;
}
int32 queuedBuffers;
AudioBackend::Source::GetQueuedBuffersCount(this, queuedBuffers);
if (!UseStreaming() && Math::NearEqual(GetTime(), 0.0f) && queuedBuffers > 0 && _isActuallyPlayingSth && !_startingToPlay)
{
if (GetIsLooping())
{
Stop();
Play();
}
else
{
Stop();
}
}
// Skip other update logic if it's not valid streamable source // Skip other update logic if it's not valid streamable source
if (!UseStreaming() || SourceIDs.IsEmpty()) if (!UseStreaming() || SourceIDs.IsEmpty())
return; return;

View File

@@ -57,6 +57,7 @@ private:
bool _clipChanged = false; bool _clipChanged = false;
bool _isActuallyPlayingSth = false; bool _isActuallyPlayingSth = false;
bool _startingToPlay = false;
bool _needToUpdateStreamingBuffers = false; bool _needToUpdateStreamingBuffers = false;
States _state = States::Stopped; States _state = States::Stopped;