diff --git a/taglib/fileref.cpp b/taglib/fileref.cpp index 8e4272dd..93a72407 100644 --- a/taglib/fileref.cpp +++ b/taglib/fileref.cpp @@ -205,12 +205,17 @@ File *FileRef::create(FileName fileName, bool readAudioProperties, int pos = s.rfind("."); if(pos != -1) { String ext = s.substr(pos + 1).upper(); - if(ext == "OGG" || ext == "OGA") - return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle); if(ext == "MP3") return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle); - if(ext == "OGA") - return new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle); + if(ext == "OGG") + return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle); + if(ext == "OGA") { + /* .oga can be any audio in the Ogg container. First try FLAC, then Vorbis. */ + File *file = new Ogg::FLAC::File(fileName, readAudioProperties, audioPropertiesStyle); + if (file->isValid()) + return file; + return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle); + } if(ext == "FLAC") return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle); if(ext == "MPC") diff --git a/tests/test_fileref.cpp b/tests/test_fileref.cpp index 6617ccd1..b0247a39 100644 --- a/tests/test_fileref.cpp +++ b/tests/test_fileref.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include "utils.h" #ifdef HAVE_CONFIG_H #include "config.h" @@ -22,6 +24,8 @@ class TestFileRef : public CppUnit::TestFixture CPPUNIT_TEST(testSpeex); CPPUNIT_TEST(testFLAC); CPPUNIT_TEST(testMP3); + CPPUNIT_TEST(testOGA_FLAC); + CPPUNIT_TEST(testOGA_Vorbis); #ifdef TAGLIB_WITH_MP4 CPPUNIT_TEST(testMP4_1); CPPUNIT_TEST(testMP4_2); @@ -131,6 +135,20 @@ public: } #endif + void testOGA_FLAC() + { + FileRef *f = new FileRef("data/empty_flac.oga"); + CPPUNIT_ASSERT(dynamic_cast(f->file()) == NULL); + CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); + } + + void testOGA_Vorbis() + { + FileRef *f = new FileRef("data/empty_vorbis.oga"); + CPPUNIT_ASSERT(dynamic_cast(f->file()) != NULL); + CPPUNIT_ASSERT(dynamic_cast(f->file()) == NULL); + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(TestFileRef);