shadPS4/src/qt_gui/background_music_player.cpp
DanielSvoboda 5e5ca2138e
Custom Trophy images / sound | and improvements (#2539)
* Custom Trophy images

* text and button - settings

* Description

* +

* plural

* translation for 'Trophy earned!'

* Revert: translation for 'Trophy earned!'

* play audio

* fixes crash due to having too many trophies

The game 'My Name is Mayo' has so many trophies in sequence that when overlapping them, the emulator ended up crashing, so if there is something on the screen and a new trophies are achieved, it will clear and show the new one.

* Animations, config: position, duration

* -

* TR

* fix sdl/qt

* clang \O/

* Side menu with filter options. Sorting

* +TR

* fix showHiddenCheck

* Time Unlocked

* Fixes ghost text, larger image, black text in light theme

* Button - Delete Trophy

* limits the width of Description - showMaximized

* changing column positions

* useEuropeanDateFormat

en_US, zh_CN, zh_TW, ja_JP, ko_KR, lt_LT, nb_NO, nl_NL
useEuropeanDateFormat = false
2025-02-28 08:31:42 +02:00

44 lines
1.3 KiB
C++

// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "background_music_player.h"
BackgroundMusicPlayer::BackgroundMusicPlayer(QObject* parent) : QObject(parent) {
m_mediaPlayer = new QMediaPlayer(this);
m_audioOutput = new QAudioOutput(this);
m_mediaPlayer->setAudioOutput(m_audioOutput);
}
void BackgroundMusicPlayer::setVolume(int volume) {
float linearVolume = QAudio::convertVolume(volume / 100.0f, QAudio::LogarithmicVolumeScale,
QAudio::LinearVolumeScale);
m_audioOutput->setVolume(linearVolume);
}
void BackgroundMusicPlayer::playMusic(const QString& snd0path, bool loops) {
if (snd0path.isEmpty()) {
stopMusic();
return;
}
const auto newMusic = QUrl::fromLocalFile(snd0path);
if (m_mediaPlayer->playbackState() == QMediaPlayer::PlayingState &&
m_currentMusic == newMusic) {
// already playing the correct music
return;
}
if (loops) {
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
} else {
m_mediaPlayer->setLoops(1);
}
m_currentMusic = newMusic;
m_mediaPlayer->setSource(newMusic);
m_mediaPlayer->play();
}
void BackgroundMusicPlayer::stopMusic() {
m_mediaPlayer->stop();
}