Constructing an ID3v2::Frame without a file
Kevin André
hyperquantum at gmail.com
Thu Aug 8 23:05:44 BST 2019
Hi Fred,
On Thu, Aug 8, 2019 at 10:29 PM Fred Gleason <fredg at paravelsystems.com> wrote:
> I have a use case where I need to parse an incoming data stream for ID3
> v2.3 tags. There are no files in this scenario, the source data is
> purely in memory (a sequence of QByteArrays, to be exact). However, all
> of the public constructors in TagLib appear to expect some sort of file
> to operate on, so I've been at a bit of a loss on how to proceed.
If the source data is a whole file that was simply loaded into memory,
you can use ByteVector and ByteVectorStream like this:
TagLib::ByteVector scratch = /* create ByteVector from QByteArray or so */;
TagLib::ByteVectorStream stream(scratch);
TagLib::MPEG::File tagFile(&stream, TagLib::ID3v2::FrameFactory::instance());
/* ... do some operations on the File object, read tags, modify them ... */
scratch = *stream.data(); /* get the modified data */
ByteVectorStream makes a copy of the ByteVector and doesn't modify the
original instance, hence the assignment at the end. Only necessary if
you want to modify the File object and then do any further processing
of the raw data.
All of this is assuming that you actually have a whole file somehow.
I don't know if it is possible to process frames independently.
- Kevin
More information about the taglib-devel
mailing list