From cd70f33ee65daa2dceb4d13fd328c73d60ba1309 Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Wed, 26 Feb 2025 01:46:31 -0300 Subject: [PATCH] play audio --- src/core/libraries/np_trophy/trophy_ui.cpp | 12 ++++++++++++ src/qt_gui/background_music_player.cpp | 9 +++++++-- src/qt_gui/background_music_player.h | 2 +- src/qt_gui/settings_dialog.cpp | 2 +- src/qt_gui/settings_dialog.ui | 2 +- src/qt_gui/translations/en_US.ts | 8 ++++---- 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/core/libraries/np_trophy/trophy_ui.cpp b/src/core/libraries/np_trophy/trophy_ui.cpp index acdc1f74a..ca14acdb0 100644 --- a/src/core/libraries/np_trophy/trophy_ui.cpp +++ b/src/core/libraries/np_trophy/trophy_ui.cpp @@ -9,6 +9,10 @@ #include #include +#ifdef ENABLE_QT_GUI +#include +#endif + #include "common/assert.h" #include "common/config.h" #include "common/singleton.h" @@ -78,6 +82,14 @@ TrophyUI::TrophyUI(const std::filesystem::path& trophyIconPath, const std::strin trophy_type_icon = RefCountedTexture::DecodePngTexture(imgdata); AddLayer(this); + +#ifdef ENABLE_QT_GUI + QString musicPath = QString::fromStdString(CustomTrophy_Dir.string() + "/trophy.mp3"); + if (fs::exists(musicPath.toStdString())) { + BackgroundMusicPlayer::getInstance().setVolume(100); + BackgroundMusicPlayer::getInstance().playMusic(musicPath, false); + } +#endif } TrophyUI::~TrophyUI() { diff --git a/src/qt_gui/background_music_player.cpp b/src/qt_gui/background_music_player.cpp index a40c5bfae..a63f1d1be 100644 --- a/src/qt_gui/background_music_player.cpp +++ b/src/qt_gui/background_music_player.cpp @@ -7,7 +7,6 @@ BackgroundMusicPlayer::BackgroundMusicPlayer(QObject* parent) : QObject(parent) m_mediaPlayer = new QMediaPlayer(this); m_audioOutput = new QAudioOutput(this); m_mediaPlayer->setAudioOutput(m_audioOutput); - m_mediaPlayer->setLoops(QMediaPlayer::Infinite); } void BackgroundMusicPlayer::setVolume(int volume) { @@ -16,7 +15,7 @@ void BackgroundMusicPlayer::setVolume(int volume) { m_audioOutput->setVolume(linearVolume); } -void BackgroundMusicPlayer::playMusic(const QString& snd0path) { +void BackgroundMusicPlayer::playMusic(const QString& snd0path, bool loops) { if (snd0path.isEmpty()) { stopMusic(); return; @@ -28,6 +27,12 @@ void BackgroundMusicPlayer::playMusic(const QString& snd0path) { return; } + if (loops) { + m_mediaPlayer->setLoops(QMediaPlayer::Infinite); + } else { + m_mediaPlayer->setLoops(1); + } + m_currentMusic = newMusic; m_mediaPlayer->setSource(newMusic); m_mediaPlayer->play(); diff --git a/src/qt_gui/background_music_player.h b/src/qt_gui/background_music_player.h index 6d70fe68c..078710a01 100644 --- a/src/qt_gui/background_music_player.h +++ b/src/qt_gui/background_music_player.h @@ -17,7 +17,7 @@ public: } void setVolume(int volume); - void playMusic(const QString& snd0path); + void playMusic(const QString& snd0path, bool loops = true); void stopMusic(); private: diff --git a/src/qt_gui/settings_dialog.cpp b/src/qt_gui/settings_dialog.cpp index 654e9c3ad..d3bc3851d 100644 --- a/src/qt_gui/settings_dialog.cpp +++ b/src/qt_gui/settings_dialog.cpp @@ -609,7 +609,7 @@ void SettingsDialog::updateNoteTextEdit(const QString& elementName) { //User if (elementName == "OpenCustomTrophyLocationButton") { - text = tr("Open custom trophy images folder:\\nIt is possible to add custom images to the trophies.\\nAdd the files to custom_trophy with the following names:\\nbronze.png, gold.png, platinum.png, silver.png"); + text = tr("Open the custom trophy images/sounds folder:\\nYou can add custom images to the trophies and an audio.\\nAdd the files to custom_trophy with the following names:\\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png"); } // Input diff --git a/src/qt_gui/settings_dialog.ui b/src/qt_gui/settings_dialog.ui index 5a51d1f10..2abe52f8b 100644 --- a/src/qt_gui/settings_dialog.ui +++ b/src/qt_gui/settings_dialog.ui @@ -1294,7 +1294,7 @@ - Open custom trophy images folder + Open the custom trophy images/sounds folder diff --git a/src/qt_gui/translations/en_US.ts b/src/qt_gui/translations/en_US.ts index fb66e9f94..ff00a2e4f 100644 --- a/src/qt_gui/translations/en_US.ts +++ b/src/qt_gui/translations/en_US.ts @@ -1312,8 +1312,8 @@ Trophy - Open custom trophy images folder - Open custom trophy images folder + Open the custom trophy images/sounds folder + Open the custom trophy images/sounds folder Logger @@ -1616,8 +1616,8 @@ Update Compatibility Database:\nImmediately update the compatibility database. - Open custom trophy images folder:\nIt is possible to add custom images to the trophies.\nAdd the files to custom_trophy with the following names:\nbronze.png, gold.png, platinum.png, silver.png - Open custom trophy images folder:\nIt is possible to add custom images to the trophies.\nAdd the files to custom_trophy with the following names:\nbronze.png, gold.png, platinum.png, silver.png + Open the custom trophy images/sounds folder:\nYou can add custom images to the trophies and an audio.\nAdd the files to custom_trophy with the following names:\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png + Open the custom trophy images/sounds folder:\nYou can add custom images to the trophies and an audio.\nAdd the files to custom_trophy with the following names:\nthophy.mp3, bronze.png, gold.png, platinum.png, silver.png Never