Drunk Cat
Drunk Cat

Reputation: 503

Getting windows mp3 files properties or tags using windows api?

I want to get the list of the properties which windows is able to get in its "Details" tab under File->Properties.

I have read several old posts about this but don't know if there is a modern way to do this. Is there a new way to do this? Note that i have added custom tags in my mp3 which i want to read and some libraries like TagCSharp are not able to read but Windows is.

I ahve already tried to use WindowsAPICodePack but i dont know how to read all the tags and not only the default ones.

I have also read this post How do I get details from File Properties? But i have not found any way to implement in in .net

enter image description here

Upvotes: 0

Views: 966

Answers (1)

Castorix
Castorix

Reputation: 1545

There are several ways.

A simple one is to use the Shell.

Test on a mp3 file (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))))));
    }
}

I get for the first properties (french) =>

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

Upvotes: 1

Related Questions