mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-06-01 08:13:16 +00:00
Add playback of background/title music in game list (#1033)
* add playback of background/title music * clang_format * add windows multimedia build instructions * fix typo accidentally made to arm * address comments * loop music * feedback * fix CI * add newline * playBGM off by default --------- Co-authored-by: Charles <charles@superfocus.ai>
This commit is contained in:
parent
ddb82a690b
commit
54e2179337
17 changed files with 181 additions and 17 deletions
32
src/qt_gui/background_music_player.cpp
Normal file
32
src/qt_gui/background_music_player.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
// 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);
|
||||
m_mediaPlayer->setLoops(QMediaPlayer::Infinite);
|
||||
}
|
||||
|
||||
void BackgroundMusicPlayer::playMusic(const QString& snd0path) {
|
||||
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;
|
||||
}
|
||||
|
||||
m_currentMusic = newMusic;
|
||||
m_mediaPlayer->setSource(newMusic);
|
||||
m_mediaPlayer->play();
|
||||
}
|
||||
|
||||
void BackgroundMusicPlayer::stopMusic() {
|
||||
m_mediaPlayer->stop();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue