mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Made sure SoundStream adhered to its documented behavior, added a hint to SoundStream and Sound documentation regarding setting the offset while stopped.
This commit is contained in:
parent
09aae0240d
commit
74e425a9ed
@ -144,7 +144,9 @@ public :
|
||||
/// \brief Change the current playing position of the sound
|
||||
///
|
||||
/// The playing position can be changed when the sound is
|
||||
/// either paused or playing.
|
||||
/// either paused or playing. Changing the playing position
|
||||
/// when the sound is stopped has no effect, since playing
|
||||
/// the sound would reset its position.
|
||||
///
|
||||
/// \param timeOffset New playing position, from the beginning of the sound
|
||||
///
|
||||
|
@ -132,7 +132,9 @@ public :
|
||||
/// \brief Change the current playing position of the stream
|
||||
///
|
||||
/// The playing position can be changed when the stream is
|
||||
/// either paused or playing.
|
||||
/// either paused or playing. Changing the playing position
|
||||
/// when the stream is stopped has no effect, since playing
|
||||
/// the stream would reset its position.
|
||||
///
|
||||
/// \param timeOffset New playing position, from the beginning of the stream
|
||||
///
|
||||
|
@ -92,17 +92,29 @@ void SoundStream::play()
|
||||
return;
|
||||
}
|
||||
|
||||
bool isStreaming = false;
|
||||
Status threadStartState = Stopped;
|
||||
|
||||
{
|
||||
Lock lock(m_threadMutex);
|
||||
|
||||
// If the sound is already playing (probably paused), just resume it
|
||||
if (m_isStreaming)
|
||||
{
|
||||
alCheck(alSourcePlay(m_source));
|
||||
return;
|
||||
}
|
||||
isStreaming = m_isStreaming;
|
||||
threadStartState = m_threadStartState;
|
||||
}
|
||||
|
||||
m_isStreaming = true;
|
||||
|
||||
if (isStreaming && (threadStartState == Paused))
|
||||
{
|
||||
// If the sound is paused, resume it
|
||||
Lock lock(m_threadMutex);
|
||||
m_threadStartState = Playing;
|
||||
alCheck(alSourcePlay(m_source));
|
||||
return;
|
||||
}
|
||||
else if (isStreaming && (threadStartState == Playing))
|
||||
{
|
||||
// If the sound is playing, stop it and continue as if it was stopped
|
||||
stop();
|
||||
}
|
||||
|
||||
// Move to the beginning
|
||||
@ -110,6 +122,7 @@ void SoundStream::play()
|
||||
|
||||
// Start updating the stream in a separate thread to avoid blocking the application
|
||||
m_samplesProcessed = 0;
|
||||
m_isStreaming = true;
|
||||
m_threadStartState = Playing;
|
||||
m_thread.launch();
|
||||
}
|
||||
@ -121,6 +134,10 @@ void SoundStream::pause()
|
||||
// Handle pause() being called before the thread has started
|
||||
{
|
||||
Lock lock(m_threadMutex);
|
||||
|
||||
if (!m_isStreaming)
|
||||
return;
|
||||
|
||||
m_threadStartState = Paused;
|
||||
}
|
||||
|
||||
@ -139,6 +156,12 @@ void SoundStream::stop()
|
||||
|
||||
// Wait for the thread to terminate
|
||||
m_thread.wait();
|
||||
|
||||
// Move to the beginning
|
||||
onSeek(Time::Zero);
|
||||
|
||||
// Reset the playing position
|
||||
m_samplesProcessed = 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user