using namespace TagLib;
+template <typename T>
+static File* createInternal(T arg, const String& filename, bool readAudioProperties,
+ AudioProperties::ReadStyle audioPropertiesStyle);
+
class FileRef::FileRefPrivate : public RefCounter
{
public:
d = new FileRefPrivate(create(fileName, readAudioProperties, audioPropertiesStyle));
}
+FileRef::FileRef(IOStream* stream, bool readAudioProperties, AudioProperties::ReadStyle audioPropertiesStyle)
+{
+ d = new FileRefPrivate(createInternal(stream,
+#ifdef _WIN32
+ stream->name().toString()
+#else
+ stream->name()
+#endif
+ , readAudioProperties, audioPropertiesStyle));
+}
+
FileRef::FileRef(File *file)
{
d = new FileRefPrivate(file);
return file;
}
- // Ok, this is really dumb for now, but it works for testing.
-
- String ext;
- {
+ return createInternal(fileName,
#ifdef _WIN32
-
- String s = fileName.toString();
-
+ fileName.toString()
#else
+ fileName
+#endif
+ , readAudioProperties, audioPropertiesStyle);
+}
- String s = fileName;
-
- #endif
+template <typename T>
+static File* createInternal(T fileName, const String& s, bool readAudioProperties,
+ AudioProperties::ReadStyle audioPropertiesStyle)
+{
+ // Ok, this is really dumb for now, but it works for testing.
- const int pos = s.rfind(".");
- if(pos != -1)
- ext = s.substr(pos + 1).upper();
- }
+ String ext;
+ const int pos = s.rfind(".");
+ if(pos != -1)
+ ext = s.substr(pos + 1).upper();
// If this list is updated, the method defaultFileExtensions() should also be
// updated. However at some point that list should be created at the same time
if(!ext.isEmpty()) {
if(ext == "MP3")
- return new MPEG::File(fileName, readAudioProperties, audioPropertiesStyle);
+ return new MPEG::File(fileName, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
if(ext == "OGG")
return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "OGA") {
return new Ogg::Vorbis::File(fileName, readAudioProperties, audioPropertiesStyle);
}
if(ext == "FLAC")
- return new FLAC::File(fileName, readAudioProperties, audioPropertiesStyle);
+ return new FLAC::File(fileName, ID3v2::FrameFactory::instance(), readAudioProperties, audioPropertiesStyle);
if(ext == "MPC")
return new MPC::File(fileName, readAudioProperties, audioPropertiesStyle);
if(ext == "WV")
audioPropertiesStyle = AudioProperties::Average);
/*!
- * Construct a FileRef using \a file. The FileRef now takes ownership of the
+ * Construct a FileRef from an opened \a IOStream. If \a readAudioProperties is true then
+ * the audio properties will be read using \a audioPropertiesStyle. If
+ * \a readAudioProperties is false then \a audioPropertiesStyle will be
+ * ignored.
+ *
+ * Also see the note in the class documentation about why you may not want to
+ * use this method in your application.
+ */
+ explicit FileRef(IOStream* stream,
+ bool readAudioProperties = true,
+ AudioProperties::ReadStyle
+ audioPropertiesStyle = AudioProperties::Average);
+
+ /*!
+ * Contruct a FileRef using \a file. The FileRef now takes ownership of the
* pointer and will delete the File when it passes out of scope.
*/
explicit FileRef(File *file);
#include <vorbisfile.h>
#include <cppunit/extensions/HelperMacros.h>
#include "utils.h"
+#include <tfilestream.h>
using namespace std;
using namespace TagLib;
CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
delete f;
+
+ FileStream fs(newname.c_str());
+ f = new FileRef(&fs);
+ CPPUNIT_ASSERT(!f->isNull());
+ CPPUNIT_ASSERT_EQUAL(f->tag()->artist(), String("ttest artist"));
+ CPPUNIT_ASSERT_EQUAL(f->tag()->title(), String("ytest title"));
+ CPPUNIT_ASSERT_EQUAL(f->tag()->genre(), String("uTest!"));
+ CPPUNIT_ASSERT_EQUAL(f->tag()->album(), String("ialbummmm"));
+ CPPUNIT_ASSERT_EQUAL(f->tag()->track(), TagLib::uint(7));
+ CPPUNIT_ASSERT_EQUAL(f->tag()->year(), TagLib::uint(2080));
+ delete f;
}
void testMusepack()