mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-28 09:33:52 +00:00
Add audio volume controls to settings
This commit is contained in:
parent
12a7604450
commit
1530900bc7
9 changed files with 79 additions and 5 deletions
|
|
@ -60,13 +60,14 @@ void MusicManager::playMusic(const std::string& mpqPath, bool loop) {
|
|||
args.push_back("0");
|
||||
}
|
||||
args.push_back("-volume");
|
||||
args.push_back("30");
|
||||
args.push_back(std::to_string(volumePercent));
|
||||
args.push_back(tempFilePath);
|
||||
|
||||
playerPid = platform::spawnProcess(args);
|
||||
if (playerPid != INVALID_PROCESS) {
|
||||
playing = true;
|
||||
currentTrack = mpqPath;
|
||||
currentTrackIsFile = false;
|
||||
LOG_INFO("Music: Playing ", mpqPath);
|
||||
} else {
|
||||
LOG_ERROR("Music: Failed to spawn ffplay process");
|
||||
|
|
@ -91,13 +92,14 @@ void MusicManager::playFilePath(const std::string& filePath, bool loop) {
|
|||
args.push_back("0");
|
||||
}
|
||||
args.push_back("-volume");
|
||||
args.push_back("30");
|
||||
args.push_back(std::to_string(volumePercent));
|
||||
args.push_back(filePath);
|
||||
|
||||
playerPid = platform::spawnProcess(args);
|
||||
if (playerPid != INVALID_PROCESS) {
|
||||
playing = true;
|
||||
currentTrack = filePath;
|
||||
currentTrackIsFile = true;
|
||||
LOG_INFO("Music: Playing file ", filePath);
|
||||
} else {
|
||||
LOG_ERROR("Music: Failed to spawn ffplay process");
|
||||
|
|
@ -109,6 +111,27 @@ void MusicManager::stopMusic(float fadeMs) {
|
|||
stopCurrentProcess();
|
||||
playing = false;
|
||||
currentTrack.clear();
|
||||
currentTrackIsFile = false;
|
||||
}
|
||||
|
||||
void MusicManager::setVolume(int volume) {
|
||||
if (volume < 0) volume = 0;
|
||||
if (volume > 100) volume = 100;
|
||||
if (volumePercent == volume) return;
|
||||
volumePercent = volume;
|
||||
if (playing && !currentTrack.empty()) {
|
||||
std::string track = currentTrack;
|
||||
bool isFile = currentTrackIsFile;
|
||||
stopCurrentProcess();
|
||||
playing = false;
|
||||
currentTrack.clear();
|
||||
currentTrackIsFile = false;
|
||||
if (isFile) {
|
||||
playFilePath(track, true);
|
||||
} else {
|
||||
playMusic(track, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::crossfadeTo(const std::string& mpqPath, float fadeMs) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue