Fixed: Only open supported music formats in music player

This commit is contained in:
kervala 2015-11-15 13:12:54 +01:00
parent 70ee2e7465
commit 2bad77c5fa
3 changed files with 83 additions and 9 deletions

View file

@ -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<std::string> &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.
}

View file

@ -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<std::string> &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

View file

@ -181,6 +181,12 @@ public:
if (Params == "play_songs")
{
std::vector<std::string> 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<std::string> 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];