Reading audio files metadata is a very frequent task. Suppose, you are making a Web site for publishing MP3 files. Of course, it is preferable to have the information about performers, titles, and so on extracted automatically. Let us see how to do it using Media Processor Add-on.
The function that will read ID3 fields should perform the following operations:
The following example simply prints the content of each ID3 field, but if you need, you can modify the code to fit your needs. For example, it can return a collection of all or only required values.
Public Sub PrintID3(ByVal inputFilename As String)
Try
'Create the reader
Dim reader As WMReader = New WMReader(inputFilename)
Dim id3 As MediaProcessorMetadataDictionary = reader.Metadata
Console.WriteLine("*** Extracted ID3 fields:")
'Iterate through all fields
For Each key As Object In id3.Keys
'Print synchronized lyrics
If key = MediaProcessorMetadataDictionary.SynchronizedLyrics Then
Console.WriteLine(id3.GetKeyDescription(key) + ":")
Dim lyrics As ID3SynchronisedLyrics = CType(id3(key), _
ID3SynchronisedLyrics)
For Each lkey As Object In lyrics.Keys
Console.WriteLine("\t" + lyrics(lkey).ToString())
Next
'Save the attached picture as a file
ElseIf key = MediaProcessorMetadataDictionary.AttachedPicture Then
Console.WriteLine("Contains an attached picture: " + _
inputFilename + ".gif")
Dim image As Aurigma.GraphicsMill.Bitmap = CType(id3(key), _
Aurigma.GraphicsMill.Bitmap)
image.Save(inputFilename + ".gif")
'Print other fields
Else
Console.WriteLine(id3.GetKeyDescription(key).ToString() + ": " _
+ id3(key).ToString())
End If
Next
reader.Dispose()
Catch ex As Exception
Console.WriteLine(ex)
End Try
End Sub
public static void PrintID3(string inputFilename)
{
try
{
//Create the reader
WMReader reader = new WMReader(inputFilename);
MediaProcessorMetadataDictionary id3 = reader.Metadata;
Console.WriteLine("*** Extracted ID3 fields:");
//Iterate through all fields
foreach (System.Object key in id3.Keys)
{
//Print synchronized lyrics
if (key.Equals(MediaProcessorMetadataDictionary.SynchronizedLyrics))
{
Console.WriteLine(id3.GetKeyDescription(key) + ":");
ID3SynchronisedLyrics lyrics =
(ID3SynchronisedLyrics)id3[key];
foreach (System.Object lkey in lyrics.Keys)
Console.WriteLine("\t" + lyrics[lkey].ToString());
}
//Save the attached picture as a file
else if (key.Equals(MediaProcessorMetadataDictionary.AttachedPicture))
{
Console.WriteLine("Contains an attached picture: " +
inputFilename + ".gif");
Aurigma.GraphicsMill.Bitmap image =
(Aurigma.GraphicsMill.Bitmap)id3[key];
image.Save(inputFilename + ".gif");
}
//Print other fields
else
Console.WriteLine(id3.GetKeyDescription(key).ToString() +
": " + id3[key].ToString());
}
reader.Dispose();
}
catch (System.Exception ex)
{
Console.WriteLine(ex);
}
}