From e1a9a437f181d5093554b902c573cd1a83ef74f8 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 8 Sep 2019 21:57:14 +0200 Subject: [PATCH] fixed pingsound not playing sometimes --- src/providers/twitch/TwitchMessageBuilder.cpp | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 6159f7563..102d570e0 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -143,9 +143,21 @@ bool TwitchMessageBuilder::isIgnored() const return false; } +inline QMediaPlayer *getPlayer() +{ + if (isGuiThread()) + { + static auto player = new QMediaPlayer; + return player; + } + else + { + return nullptr; + } +} + void TwitchMessageBuilder::triggerHighlights() { - static auto player = new QMediaPlayer; static QUrl currentPlayerUrl; if (this->historicalMessage_) @@ -165,21 +177,24 @@ void TwitchMessageBuilder::triggerHighlights() if (this->highlightSound_ && resolveFocus) { - // update the media player url if necessary - QUrl highlightSoundUrl = - getSettings()->customHighlightSound - ? QUrl::fromLocalFile( - getSettings()->pathHighlightSound.getValue()) - : QUrl("qrc:/sounds/ping2.wav"); - - if (currentPlayerUrl != highlightSoundUrl) + if (auto player = getPlayer()) { - player->setMedia(highlightSoundUrl); + // update the media player url if necessary + QUrl highlightSoundUrl = + getSettings()->customHighlightSound + ? QUrl::fromLocalFile( + getSettings()->pathHighlightSound.getValue()) + : QUrl("qrc:/sounds/ping2.wav"); - currentPlayerUrl = highlightSoundUrl; + if (currentPlayerUrl != highlightSoundUrl) + { + player->setMedia(highlightSoundUrl); + + currentPlayerUrl = highlightSoundUrl; + } + + player->play(); } - - player->play(); } if (this->highlightAlert_)