From 80ed37ce9d11f63375eacd8c0bdd7f6850431441 Mon Sep 17 00:00:00 2001 From: kimci86 Date: Mon, 1 Aug 2022 12:29:56 +0200 Subject: [PATCH] Fix SoundStream::play to restart the sound if it was played before --- src/SFML/Audio/SoundStream.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index b3be97bd..251a2457 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -136,6 +136,15 @@ void SoundStream::play() // If the sound is playing, stop it and continue as if it was stopped stop(); } + else if (!isStreaming) + { + // Either the streaming thread has never been launched or it has been launched and has reached its end. + // - If it has reached its end, we have to restart the sound from the beginning. + // - If it has never been launched, it is not necessary to move to the beginning, but it is not harmful. + // To check if the sound has never been launched would require additional complexity + // which we can avoid by moving to the beginning in both cases. + onSeek(Time::Zero); + } // Start updating the stream in a separate thread to avoid blocking the application m_isStreaming = true;