Tone player "myself" guard

This commit is contained in:
Klaus Basan
2020-03-15 00:32:31 +01:00
committed by Mat Sutcliffe
parent 5b3c011a15
commit 5718f95819
2 changed files with 8 additions and 4 deletions

View File

@@ -28,12 +28,16 @@ namespace BlackSound
void CThreadedTonePairPlayer::play(int volume, const QList<CTonePair> &tonePairs)
{
QPointer<CThreadedTonePairPlayer> myself(this);
QMutexLocker ml(&m_mutex);
if (m_audioOutput->state() != QAudio::StoppedState) { return; }
m_bufferData = this->getAudioByTonePairs(tonePairs);
m_audioOutput->setVolume(static_cast<qreal>(0.01 * volume));
QTimer::singleShot(0, this, &CThreadedTonePairPlayer::playBuffer);
QTimer::singleShot(0, this, [ = ]
{
if (myself) { myself->playBuffer(); }
});
}
bool CThreadedTonePairPlayer::reinitializeAudio(const CAudioDeviceInfo &device)