[Notification] Make sure no sound is stopped in QTimer::singleShot which is no longer playing

This commit is contained in:
Klaus Basan
2019-11-16 00:55:20 +01:00
committed by Mat Sutcliffe
parent 3a4f114308
commit 72334af1e8
2 changed files with 3 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ namespace BlackSound
{
if (!m_playingEffect && effect->isLoaded() && !effect->isPlaying())
{
const int currentEffect = ++m_playingEffectCounter;
const qreal v = volume / 100.0f;
m_playingEffect = effect;
effect->setVolume(v); // 0..1
@@ -48,6 +49,7 @@ namespace BlackSound
QTimer::singleShot(3000, effect, [ = ]
{
if (!myself || !m_playingEffect) { return; }
if (currentEffect != m_playingEffectCounter) { return; }
m_playingEffect->stop();
});
}

View File

@@ -43,6 +43,7 @@ namespace BlackSound
QHash<BlackMisc::Audio::CNotificationSounds::NotificationFlag, QSoundEffect *> m_effects;
QString m_directory;
QPointer<QSoundEffect> m_playingEffect;
int m_playingEffectCounter = 0;
//! Playing of effect has been changed
void onPlayingChanged();