我正在尝试使用 TagLib C++ API 从任意音频文件中读取 ID3v2 元数据。该文件不一定是.mp3
文件,可能是其他常见的音频格式。我有以下内容:
std::string readId3v2Tag(std::string filePath, std::string tagName) {
// read from file
TagLib::FileRef f(filePath.c_str());
if (!f.isNull() && f.file()) {
// get tags from property map
TagLib::PropertyMap tags = f.file()->properties();
if (tags.find(tag) != tags.end()) {
return std::string(tags[tag][0].toCString());
}
}
}
但是,当我输入 ID3v2 框架名称时,它不会返回任何内容。我相信这是因为f.file()->properties()
地图包含 TagLib 的标签格式。我必须能够按名称访问 ID3v2 帧。
我被告知要使用ID3v2
该类,但是我看不到如何从文件中访问它,并且在阅读 API 文档时遇到了麻烦。有谁知道如何做到这一点?