首页 > 解决方案 > 使用 windows api 获取 windows mp3 文件属性或标签?

问题描述

我想在“文件”->“属性”下的“详细信息”选项卡中获取 Windows 能够获取的属性列表。

我已经阅读了几篇关于此的旧帖子,但不知道是否有现代方法可以做到这一点。有没有新的方法可以做到这一点?请注意,我在我想要阅读的 mp3 中添加了自定义标签,并且一些库(如 TagCSharp)无法读取,但 Windows 可以。

我已经尝试过使用 WindowsAPICodePack,但我不知道如何读取所有标签,而不仅仅是默认标签。

我也读过这篇文章 如何从文件属性中获取详细信息? 但我还没有找到任何在.net中实现的方法

在此处输入图像描述

标签: .netwindowsfile-properties

解决方案


有几种方法。

一个简单的方法是使用 Shell。

测试 mp3 文件(Windows 10、C#、VS 2015)=>

// Add Reference Shell32.DLL
string sFolder = "e:\\";
string sFile= "01. IMANY - Don't Be so Shy (Filatov & Karas Remix).mp3";
List<string> arrProperties = new List<string>();
Shell objShell = new Shell();
Folder objFolder;
objFolder = objShell.NameSpace(sFolder);
int nMaxProperties = 332;
for (int i = 0; i < nMaxProperties; i++)
{
    string sHeader = objFolder.GetDetailsOf(null, i);
    arrProperties.Add(sHeader);
}
FolderItem objFolderItem = objFolder.ParseName(sFile);
if (objFolderItem != null)
{
    for (int i = 0; i < arrProperties.Count; i++)
    {
        Console.WriteLine((i + ('\t' + (arrProperties[i] + (": " + objFolder.GetDetailsOf(objFolderItem, i))))));
    }
}

我得到了第一个属性(法语)=>

0   Nom: 01. IMANY - Don't Be so Shy (Filatov & Karas Remix).mp3
1   Taille: 7,28 Mo
2   Type d’élément: Son au format MP3
3   Modifié le: 04/07/2019 22:47
4   Date de création: 21/04/2017 15:15
5   Date d’accès: 08/07/2019 12:23
6   Attributs: A
7   État hors connexion: 
8   Disponibilité: 
9   Type identifié: Audio
10  Propriétaire: DESKTOP-EOPIFM5\xxx
11  Sorte: Musique
12  Prise de vue: 
13  Interprètes ayant participé: IMANY
14  Album: Virgin Radio Summer Pop 2016
15  Année: 2016
16  Genre: Pop
17  Chefs d’orchestre: 
18  Mots clés: 
19  Notation: 4 étoiles
20  Auteurs: IMANY
21  Titre: Don't Be so Shy (Filatov & Karas Remix)
22  Objet: 
23  Catégories: 
24  Commentaires: 
25  Copyright: 
26  N°: 1
27  Longueur: 00:03:10
28  Vitesse de transmission: ?320 Kbits/s

推荐阅读