我正在尝试索引只有一个 ID3 帧的 mp3 文件。使用 CLucene 和 TagLib。以下代码工作正常:
...
TagLib::MPEG::File file("/home/user/Depeche Mode - Personal Jesus.mp3");
if (file.ID3v2Tag()) {
TagLib::ID3v2::FrameList frameList = file.ID3v2Tag()->frameList();
lucene::document::Document *document = new lucene::document::Document;
TagLib::ID3v2::FrameList::ConstIterator frame = frameList.begin();
std::wstring field_name((*frame)->frameID().begin(), (*frame)->frameID().end());
const wchar_t *fieldName = field_name.c_str();
const wchar_t *fieldValue = (*frame)->toString().toWString().c_str();
lucene::document::Field field(fieldName, fieldValue, true, true, true, false);
document->add(field);
writer->addDocument(document);
}
...
但这会使应用程序崩溃:
...
TagLib::MPEG::File file("/home/user/Depeche Mode - Personal Jesus.mp3");
if (file.ID3v2Tag()) {
TagLib::ID3v2::FrameList frameList = file.ID3v2Tag()->frameList();
lucene::document::Document *document = new lucene::document::Document;
for (TagLib::ID3v2::FrameList::ConstIterator frame = frameList.begin(); frame != frameList.end(); frame++) {
std::wstring field_name((*frame)->frameID().begin(), (*frame)->frameID().end());
const wchar_t *fieldName = field_name.c_str();
const wchar_t *fieldValue = (*frame)->toString().toWString().c_str();
lucene::document::Field field(fieldName, fieldValue, true, true, true, false);
document->add(field);
}
writer->addDocument(document);
}
...
这是为什么?!