From 72334af1e8d1adfc4143c89ae011ca804742e4ce Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 16 Nov 2019 00:55:20 +0100 Subject: [PATCH] [Notification] Make sure no sound is stopped in QTimer::singleShot which is no longer playing --- src/blacksound/notificationplayer.cpp | 2 ++ src/blacksound/notificationplayer.h | 1 + 2 files changed, 3 insertions(+) diff --git a/src/blacksound/notificationplayer.cpp b/src/blacksound/notificationplayer.cpp index c4cdbbfc9..58a910f13 100644 --- a/src/blacksound/notificationplayer.cpp +++ b/src/blacksound/notificationplayer.cpp @@ -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(); }); } diff --git a/src/blacksound/notificationplayer.h b/src/blacksound/notificationplayer.h index 38f64851b..28c0d9988 100644 --- a/src/blacksound/notificationplayer.h +++ b/src/blacksound/notificationplayer.h @@ -43,6 +43,7 @@ namespace BlackSound QHash m_effects; QString m_directory; QPointer m_playingEffect; + int m_playingEffectCounter = 0; //! Playing of effect has been changed void onPlayingChanged();