From 80d4f699735155cd6e92deff40018beabf6cc45f Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 15 Nov 2015 13:12:54 +0100 Subject: [PATCH] Fixed: Only open supported music formats in music player --- code/nel/src/sound/audio_decoder.cpp | 7 +- code/nel/src/sound/audio_mixer_user.cpp | 10 ++- .../client/src/interface_v3/music_player.cpp | 75 +++++++++++++++++-- 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/code/nel/src/sound/audio_decoder.cpp b/code/nel/src/sound/audio_decoder.cpp index 74193949c..d8283c227 100644 --- a/code/nel/src/sound/audio_decoder.cpp +++ b/code/nel/src/sound/audio_decoder.cpp @@ -124,7 +124,12 @@ bool IAudioDecoder::getInfo(const std::string &filepath, std::string &artist, st /// Get audio/container extensions that are currently supported by the nel sound library. void IAudioDecoder::getMusicExtensions(std::vector &extensions) { - extensions.push_back("ogg"); + // only add ogg format if not already in extensions list + if (std::find(extensions.begin(), extensions.end(), "ogg") == extensions.end()) + { + extensions.push_back("ogg"); + } + // extensions.push_back("wav"); // TODO: Easy. } diff --git a/code/nel/src/sound/audio_mixer_user.cpp b/code/nel/src/sound/audio_mixer_user.cpp index 3a75433f4..bb79359e1 100644 --- a/code/nel/src/sound/audio_mixer_user.cpp +++ b/code/nel/src/sound/audio_mixer_user.cpp @@ -54,6 +54,7 @@ #include "nel/sound/sound_bank.h" #include "nel/sound/group_controller.h" #include "nel/sound/containers.h" +#include "nel/sound/audio_decoder.h" using namespace std; using namespace NLMISC; @@ -2751,7 +2752,14 @@ bool CAudioMixerUser::isEventMusicEnded() /// Get audio/container extensions that are currently supported by nel or the used driver implementation. void CAudioMixerUser::getMusicExtensions(std::vector &extensions) { - _SoundDriver->getMusicExtensions(extensions); + if (_SoundDriver) + { + // add file formats supported by driver + _SoundDriver->getMusicExtensions(extensions); + } + + // add 3rd party libraries support file formats + IAudioDecoder::getMusicExtensions(extensions); } /// Add a reverb environment diff --git a/code/ryzom/client/src/interface_v3/music_player.cpp b/code/ryzom/client/src/interface_v3/music_player.cpp index 171fc328e..639c170c0 100644 --- a/code/ryzom/client/src/interface_v3/music_player.cpp +++ b/code/ryzom/client/src/interface_v3/music_player.cpp @@ -181,6 +181,12 @@ public: if (Params == "play_songs") { + std::vector extensions; + SoundMngr->getMixer()->getMusicExtensions(extensions); + + // no format supported + if (extensions.empty()) return; + #ifdef NL_OS_WINDOWS // Backup the current directory string currentPath = CPath::getCurrentPath (); @@ -195,13 +201,68 @@ public: } else { - static char szFilter[] = - "All Supported Files\0*.mp3;*.mp2;*.mp1;*.ogg;*.m3u\0" - "MPEG Audio Files (*.mp3;*.mp2;*.mp1)\0*.mp3;*.mp2;*.mp1\0" - "Vorbis Files (*.ogg)\0*.ogg\0" - "Playlist Files (*.m3u)\0*.m3u\0" - "All Files (*.*)\0*.*\0" - "\0"; + bool oggSupported = false; + bool mp3Supported = false; + + for(uint i = 0; i < extensions.size(); ++i) + { + if (extensions[i] == "ogg") + { + oggSupported = true; + } + else if (extensions[i] == "mp3") + { + mp3Supported = true; + } + } + + std::vector filters; + + // supported formats + filters.push_back("All Supported Files"); + + std::string filter; + if (mp3Supported) filter += "*.mp3;*.mp2;*.mp1;"; + if (oggSupported) filter += "*.ogg;"; + filter += "*.m3u"; + + filters.push_back(filter); + + // mp3 format + if (mp3Supported) + { + filters.push_back("MPEG Audio Files (*.mp3;*.mp2;*.mp1)"); + filters.push_back("*.mp3;*.mp2;*.mp1"); + } + + // ogg format + if (oggSupported) + { + filters.push_back("Vorbis Files (*.ogg)"); + filters.push_back("*.ogg"); + } + + // playlist + filters.push_back("Playlist Files (*.m3u)"); + filters.push_back("*.m3u"); + + // all files + filters.push_back("All Files (*.*)"); + filters.push_back("*.*"); + + filters.push_back(""); + + static char szFilter[1024] = { '\0' }; + + uint offset = 0; + + for(uint i = 0; i < filters.size(); ++i) + { + strcpy(szFilters + offset, filters[i].c_str()); + + // move offset to string length + 1 for \0 + offset += filters[i].length() + 1; + } // Filename buffer char buffer[65535];