如何使用 IPropertyStore 通过 C++ 访问 Windows 中的 mp3 元数据?
给定 mp3 文件的路径,
如何创建并初始化 IPropertyStore 对象以对该文件的元数据进行操作?
具体来说,我如何从这里:
"C:\\Music\\Viva Las Vegas.mp3"
到这里:
store->GetValue(PKEY_Music_AlbumArtist, &variant);
这里有一些伪内容代码来帮助澄清我想要做的事情:
#include "stdafx.h"
#include <propsys.h>
#include <propkey.h>
void main ()
{
// property store must somehow represent the mp3 file
IPropertyStore* store = "C:\\Music\\Viva Las Vegas.mp3"; // HELP!
PROPVARIANT variant;
// get the existing album artist
store->GetValue(PKEY_Music_AlbumArtist, &variant);
assert(variant== "Elvis Presley");
// set it to something else
variant= "ZZ Top";
store->SetValue(PKEY_Music_AlbumArtist, variant);
}
背景
也许有更好的语言可以做到这一点,但我想使用C++(这是一个很长的故事)。
最初,在研究了 mp3 元数据之后,似乎使用 TagLib 的 ID3 标签是正确的选择。因此,我编写了一个在几个领域运行良好的实用程序。但后来我发现 TagLib 仅限于许多可能字段的一小部分,而我想访问所有这些字段。
我最关心的字段是专辑艺术家,因为 Windows Media Player 使用它作为默认排序顺序,无法更改。
我修改了 TagLib 源以访问专辑艺术家而不是贡献艺术家(通过将所有出现的“\251ART”更改为“\141ART”),但它不起作用。
我确信有一种方法可以使用 ID3 标签完成所有工作,但我不想依赖额外的东西,例如 TagLib、ZLIB 和 CMake 工具。我想使用 IPropertyStore,因为它是内置的,如果我能克服这个障碍,这似乎是最简单的方法。
我在网上找到了一些 IPropertyStore 的示例,我尝试按摩它们以满足我的需要,但没有任何运气,我仍然很困惑。
MSDN“帮助”一点帮助都没有——没有规范,没有示例——它甚至没有告诉我要包含哪个头文件。与以前相比,MSDN 帮助现在很糟糕,或者我错过了什么?没有谷歌我就完蛋了。无论如何......
我希望有人可以用 3 或 4 行代码向我展示如何为我的目的创建和初始化 IPropertyStore。提前致谢。
Given the path of an mp3 file,
how do I create and initialize an IPropertyStore object to operate on the metadata of that file?
Specifically, how do I get from here:
"C:\\Music\\Viva Las Vegas.mp3"
to here:
store->GetValue(PKEY_Music_AlbumArtist, &variant);
Here's some pseudo-ish code to help clarify what I'm trying to do:
#include "stdafx.h"
#include <propsys.h>
#include <propkey.h>
void main ()
{
// property store must somehow represent the mp3 file
IPropertyStore* store = "C:\\Music\\Viva Las Vegas.mp3"; // HELP!
PROPVARIANT variant;
// get the existing album artist
store->GetValue(PKEY_Music_AlbumArtist, &variant);
assert(variant== "Elvis Presley");
// set it to something else
variant= "ZZ Top";
store->SetValue(PKEY_Music_AlbumArtist, variant);
}
BACKGROUND
Perhaps there is a better language for doing this but I want to use C++ (it's a long story).
Originally, after researching mp3 metadata, it seemed like ID3 tags with TagLib was the way to go. So I wrote a utility that worked fine on a couple of fields. But then I discovered that TagLib is limited to a small subset of the many possible fields, and I want access to all of them.
The field I'm most concerned with is Album Artist because Windows Media Player uses it as the default sort order which cannot be changed.
I modified the TagLib source to access the Album artist instead of the Contributing artist (by changing all occurrences of '\251ART' to '\141ART') but it didn't work.
I'm sure there is a way that everything can be done with ID3 tags but I'd rather not rely on extra stuff like TagLib, ZLIB and the CMake facility. I want to use IPropertyStore because it's built in, and it seems like the simplest way if I can just get over this hurdle.
I found a few examples of IPropertyStore on the web, and I've tried to massage them to suit my needs without any luck, I am still mystified.
MSDN "Help" isn't the least bit helpful -- no specs, no examples -- it doesn't even tell me which header file to include. MSDN Help is terrible now compared to what it used to be, or am I missing something? Without Google I'd be screwed. Anyway ...
I hope someone can show me in 3 or 4 lines of code how to create and initialize IPropertyStore for my purpose. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案如下:
感谢 Logan Capaldo 为我指明了正确的方向。当我发现时我不需要这两个功能
Here's the answer:
Thanks to Logan Capaldo for pointing me in the right direction. I didn't need those 2 functions when I found
简而言之,SHParseDisplayName 获取 PIDL,您可以将其提供给 SHGetPropertyStoreFromIDList
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762236(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762196(v=vs.85).aspx
Briefly, SHParseDisplayName to get a PIDL you can give to SHGetPropertyStoreFromIDList
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762236(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/bb762196(v=vs.85).aspx