From b8780fa1af4cc8bdb338c8970fd07e6696c520fc Mon Sep 17 00:00:00 2001 From: Rimi Kanokawa Date: Sun, 19 Jan 2025 11:28:59 +0000 Subject: [PATCH] Add support for using OGG music instead of MP3 music. --- coreengine/audiomanager.cpp | 20 ++++++++++++++++---- coreengine/audiomanager.h | 1 + distribution/build_linux_appimage.sh | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/coreengine/audiomanager.cpp b/coreengine/audiomanager.cpp index c46182bb6..6357ffd9e 100644 --- a/coreengine/audiomanager.cpp +++ b/coreengine/audiomanager.cpp @@ -448,7 +448,7 @@ void AudioManager::loadMediaForFile(QString filePath, qint32 position) file.open(QIODevice::ReadOnly); m_player->m_content = file.readAll(); m_player->m_fileStream.open(QIODevice::ReadOnly); - m_player->m_player.setSourceDevice(&(m_player->m_fileStream)); + m_player->m_player.setSourceDevice(&(m_player->m_fileStream), GlobalUtils::getUrlForFile(filePath)); m_player->m_player.setPosition(position); } #endif @@ -554,7 +554,7 @@ void AudioManager::slotSetMuteInternal(bool value) } } -void AudioManager::SlotAddMusic(QString file, qint64 startPointMs, qint64 endPointMs) +bool AudioManager::tryAddMusic(QString file, qint64 startPointMs, qint64 endPointMs) { #ifdef AUDIOSUPPORT if (!m_noAudio) @@ -580,7 +580,18 @@ void AudioManager::SlotAddMusic(QString file, qint64 startPointMs, qint64 endPoi CONSOLE_PRINT("Unable to locate music file: " + currentPath, GameConsole::eERROR); } } - #endif +#endif +} + +void AudioManager::SlotAddMusic(QString file, qint64 startPointMs, qint64 endPointMs) +{ +#ifdef AUDIOSUPPORT + bool success = tryAddMusic(file, startPointMs, endPointMs); + if (!success && file.endsWith(".wav") || file.endsWith(".mp3")) + { + tryAddMusic(file.first(file.length() - 4) + ".ogg", startPointMs, endPointMs); + } +#endif } #ifdef AUDIOSUPPORT @@ -656,7 +667,8 @@ void AudioManager::loadMusicFolder(const QString & folder, QStringList& loadedSo QDir directory(folder); if (directory.exists()) { - QStringList filter("*.mp3"); + QStringList filter; + filter << "*.mp3" << "*.wav" << "*.ogg"; QStringList files = directory.entryList(filter); for (const auto& file : files) { diff --git a/coreengine/audiomanager.h b/coreengine/audiomanager.h index 4aefb38cb..b50f85e4e 100644 --- a/coreengine/audiomanager.h +++ b/coreengine/audiomanager.h @@ -309,6 +309,7 @@ protected slots: qint32 m_endpointMs{-1}; QString m_file; }; + bool tryAddMusic(QString file, qint64 startPointMs, qint64 endPointMs); #ifdef AUDIOSUPPORT spPlayer m_player; QVector m_PlayListdata; diff --git a/distribution/build_linux_appimage.sh b/distribution/build_linux_appimage.sh index f7f459d5a..a907de166 100755 --- a/distribution/build_linux_appimage.sh +++ b/distribution/build_linux_appimage.sh @@ -58,6 +58,7 @@ EXCLUDES_LIST=" --exclude-library *libqtiff* --exclude-library *libqwbmp* --exclude-library *libqwebp* + --exclude-library *libgstreamermediaplugin* " $LINUXDEPLOY --appdir=distribution/AppDir \ -i distribution/res/icons/ico${SIDE}_linux_16.png --icon-filename=commander_wars_ico${SIDE} \