play audio

This commit is contained in:
DanielSvoboda 2025-02-26 01:46:31 -03:00
parent a9a72d9d72
commit cd70f33ee6
6 changed files with 26 additions and 9 deletions

View File

@ -9,6 +9,10 @@
#include <common/path_util.h>
#include <imgui.h>
#ifdef ENABLE_QT_GUI
#include <qt_gui/background_music_player.h>
#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() {

View File

@ -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();

View File

@ -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:

View File

@ -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

View File

@ -1294,7 +1294,7 @@
<item>
<widget class="QPushButton" name="OpenCustomTrophyLocationButton">
<property name="text">
<string>Open custom trophy images folder</string>
<string>Open the custom trophy images/sounds folder</string>
</property>
</widget>
</item>

View File

@ -1312,8 +1312,8 @@
<translation>Trophy</translation>
</message>
<message>
<source>Open custom trophy images folder</source>
<translation>Open custom trophy images folder</translation>
<source>Open the custom trophy images/sounds folder</source>
<translation>Open the custom trophy images/sounds folder</translation>
</message>
<message>
<source>Logger</source>
@ -1616,8 +1616,8 @@
<translation>Update Compatibility Database:\nImmediately update the compatibility database.</translation>
</message>
<message>
<source>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</source>
<translation>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</translation>
<source>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</source>
<translation>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</translation>
</message>
<message>
<source>Never</source>