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
|
/// \brief Change the current playing position of the sound
|
||||||
///
|
///
|
||||||
/// The playing position can be changed when the sound is
|
/// 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
|
/// \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
|
/// \brief Change the current playing position of the stream
|
||||||
///
|
///
|
||||||
/// The playing position can be changed when the stream is
|
/// 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
|
/// \param timeOffset New playing position, from the beginning of the stream
|
||||||
///
|
///
|
||||||
|
@ -92,17 +92,29 @@ void SoundStream::play()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isStreaming = false;
|
||||||
|
Status threadStartState = Stopped;
|
||||||
|
|
||||||
{
|
{
|
||||||
Lock lock(m_threadMutex);
|
Lock lock(m_threadMutex);
|
||||||
|
|
||||||
// If the sound is already playing (probably paused), just resume it
|
isStreaming = m_isStreaming;
|
||||||
if (m_isStreaming)
|
threadStartState = m_threadStartState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isStreaming && (threadStartState == Paused))
|
||||||
{
|
{
|
||||||
|
// If the sound is paused, resume it
|
||||||
|
Lock lock(m_threadMutex);
|
||||||
|
m_threadStartState = Playing;
|
||||||
alCheck(alSourcePlay(m_source));
|
alCheck(alSourcePlay(m_source));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if (isStreaming && (threadStartState == Playing))
|
||||||
m_isStreaming = true;
|
{
|
||||||
|
// If the sound is playing, stop it and continue as if it was stopped
|
||||||
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move to the beginning
|
// Move to the beginning
|
||||||
@ -110,6 +122,7 @@ void SoundStream::play()
|
|||||||
|
|
||||||
// Start updating the stream in a separate thread to avoid blocking the application
|
// Start updating the stream in a separate thread to avoid blocking the application
|
||||||
m_samplesProcessed = 0;
|
m_samplesProcessed = 0;
|
||||||
|
m_isStreaming = true;
|
||||||
m_threadStartState = Playing;
|
m_threadStartState = Playing;
|
||||||
m_thread.launch();
|
m_thread.launch();
|
||||||
}
|
}
|
||||||
@ -121,6 +134,10 @@ void SoundStream::pause()
|
|||||||
// Handle pause() being called before the thread has started
|
// Handle pause() being called before the thread has started
|
||||||
{
|
{
|
||||||
Lock lock(m_threadMutex);
|
Lock lock(m_threadMutex);
|
||||||
|
|
||||||
|
if (!m_isStreaming)
|
||||||
|
return;
|
||||||
|
|
||||||
m_threadStartState = Paused;
|
m_threadStartState = Paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +156,12 @@ void SoundStream::stop()
|
|||||||
|
|
||||||
// Wait for the thread to terminate
|
// Wait for the thread to terminate
|
||||||
m_thread.wait();
|
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