5

我正在为 Media Center(Windows 7 附带的版本)编写一个加载项,并希望检索用户包含在媒体库(图片、视频、录制的电视、电影、音乐)中的物理目录列表.

Media Center 对象模型 ( Microsoft.MediaCenter.*) 似乎没有任何规定可以获取此信息。

注册表在 处有一个键HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Media Center\MediaFolders,但是这些总是空的。

中似乎有完整的目录列表%userprofile%\AppData\Local\Microsoft\Media Player\wmpfolders.wmdb,但无法判断每个目录与哪个媒体库相关,并且由于这些是媒体播放器的设置,它们的存在可能只是巧合。

有谁知道如何可靠地检索这些目录的列表,最好是从插件程序集中(即使用 C#)?

4

2 回答 2

3

我使用 Reflector 来了解 ehshell 是如何做到这一点的。对于图片、视频、音乐和录制的电视,它使用从 ehuihlp.dll 导入的方法。对于电影,它只是直接从HKCR\Software\Microsoft\Windows\CurrentVersion\Media Center\MediaFolders\Movie.

以下是如何使用导入方法的示例:

using System.Runtime.InteropServices;

...

[DllImport(@"c:\Windows\ehome\ehuihlp.dll", CharSet = CharSet.Unicode)]
static extern int EhGetLocationsForLibrary(ref Guid knownFolderGuid, [MarshalAs(UnmanagedType.SafeArray)] out string[] locations);

...

Guid RecordedTVLibrary = new Guid("1a6fdba2-f42d-4358-a798-b74d745926c5");
Guid MusicLibrary = new Guid("2112ab0a-c86a-4ffe-a368-0de96e47012e");
Guid PicturesLibrary = new Guid("a990ae9f-a03b-4e80-94bc-9912d7504104");
Guid VideosLibrary = new Guid("491e922f-5643-4af4-a7eb-4e7a138d8174")

...

string[] locations;
EhGetLocationsForLibrary(ref PicturesLibrary, out locations);
于 2011-03-16T21:36:55.030 回答
0
private void ListItems(ListMakerItem listMakerItem)
{
    if (listMakerItem.MediaTypes == Microsoft.MediaCenter.ListMaker.MediaTypes.Folder)
    {
        // Recurse into Folders
        ListMakerList lml = listMakerItem.Children;
        foreach (ListMakerItem listMakerChildItem in lml)
        {
            ListItems(listMakerChildItem);
        }
     }
     else
     {
        BuildDirectoryList(listMakerItem.FileName)
     }
}

private void BuildDirectoryList(string fileName)
{
   // Parse fileName and build unique directory list
}

这是一种间接方式,但可以让您构建所需的目录列表。有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/ee525804.aspx

于 2011-03-16T17:24:36.827 回答