diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index c990332a0..e85280f90 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -338,6 +338,7 @@ void AudioSource::PlayInternal() AudioBackend::Source::Play(this); _isActuallyPlayingSth = true; + _startingToPlay = true; } #if USE_EDITOR @@ -419,6 +420,27 @@ void AudioSource::Update() 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 if (!UseStreaming() || SourceIDs.IsEmpty()) return; diff --git a/Source/Engine/Audio/AudioSource.h b/Source/Engine/Audio/AudioSource.h index 450edf44a..57aab9dc8 100644 --- a/Source/Engine/Audio/AudioSource.h +++ b/Source/Engine/Audio/AudioSource.h @@ -57,6 +57,7 @@ private: bool _clipChanged = false; bool _isActuallyPlayingSth = false; + bool _startingToPlay = false; bool _needToUpdateStreamingBuffers = false; States _state = States::Stopped;