Aurigma Graphics Mill 5.5 for .NET
Reading Metadata
In terms of Media Processor Add-on, metadata is a set of data that are stored in a file and describe this file. There is no single metadata schema for multimedia, as media files in different formats provide different metadata. However, Media Processor Add-on exposes a universal interface to get such information.
Despite the format variety, there are three main kinds of metadata that are generally used:
- Simple fields with text values.
- Synchronized lyrics.
- Non-text fields—bitmap images.
Let us look at them one by one.
Reading Text Data
In Media Processor Add-on, readers are the main source of information about files that are opened with them. No wonder, the readers are used to get file metadata too.
In order to read simple text metadata, do the following:
- Get the MediaProcessorMetadataDictionary instance stored in the QTReader.Metadata or the WMReader.Metadata property, depending on the type of the reader you use.
- Read values in the way that is convenient to you:
- Read certain fields that you are interested in. For that pass the corresponding keys to the Item(Object) property. To check if the required fields are stored with the file, call the Contains(Object) method.
- Loop through all fields using the Keys collection.
For the list of available MediaProcessorMetadataDictionary fields, see the MediaProcessorMetadataDictionary Fields topic. This set of fields is based mostly on the ID3v2 standard.
The following sample shows how to get an MediaProcessorMetadataDictionary object with metadata for the opened file and print all text fields.
Visual Basic
'Get all metadata
Private Sub GetMetadata(ByVal fileName As String)
Dim _reader As New WMReader(fileName)
Dim tags As MediaProcessorMetadataDictionary = _reader.Metadata
'Print all text fields
For Each key As Object In tags.Keys
If key <> MediaProcessorMetadataDictionary.SynchronizedLyrics And _
key <> MediaProcessorMetadataDictionary.AttachedPicture Then
Console.WriteLine(tags.GetKeyDescription(key).ToString() & _
": " & tags(key).ToString())
End If
Next
End Sub
C#
//Get all metadata
private void GetMetadata(String fileName)
{
WMReader _reader = new WMReader(fileName);
MediaProcessorMetadataDictionary tags = _reader.Metadata;
//Print all text fields
foreach (System.Object key in tags.Keys)
if (!key.Equals(MediaProcessorMetadataDictionary.SynchronizedLyrics) &&
!key.Equals(MediaProcessorMetadataDictionary.AttachedPicture))
Console.WriteLine(tags.GetKeyDescription(key).ToString() +
": " + tags[key].ToString());
}
Reading Synchronized Lyrics
Synchronized lyrics are different from simple text metadata, as they are intended to appear during song playback at certain points of time. So they contain not only text, but also timestamps.
In order to read synchronized lyrics, do the following:
- Get the MediaProcessorMetadataDictionary instance, as described above.
- Check if the SynchronizedLyrics field is stored with the file calling the Contains(Object) method. Another option is to iterate through the Keys collection until you find a key of this type.
- Read the value of the SynchronizedLyrics field into the variable of the ID3SynchronisedLyrics type. This object is also a dictionary. Its keys are time values in the TimestampFormat, and its values are lyrics.
Visual Basic
'Get synchronized lyrics
Private Sub GetLyrics(ByVal metadata As MediaProcessorMetadataDictionary)
'Check if lyrics are present
If metadata.Contains(MediaProcessorMetadataDictionary.SynchronizedLyrics) Then
Dim lyrics As ID3SynchronisedLyrics = CType(metadata _
(MediaProcessorMetadataDictionary.SynchronizedLyrics), _
ID3SynchronisedLyrics)
'Process lyrics
'...
Return
End If
MessageBox.Show("Lyrics are absent", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Sub
C#
//Get synchronized lyrics
private void GetLyrics(MediaProcessorMetadataDictionary metadata)
{
//Check if lyrics are present
if (metadata.Contains(MediaProcessorMetadataDictionary.SynchronizedLyrics))
{
ID3SynchronisedLyrics lyrics = (ID3SynchronisedLyrics)metadata
[MediaProcessorMetadataDictionary.SynchronizedLyrics];
//Process lyrics
//...
return;
}
MessageBox.Show("Lyrics are absent", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
Reading Bitmap Images
Some media files include bitmap images among other metadata. Such images usually represent album covers, performer photographs, and so on.
There are two ways of reading bitmap images.
The first approach is to apply the standard frame-by-frame reading technique. It is described in the Reading Video Files Frame by Frame topic.
The other method involves a metadata dictionary:
- Get the MediaProcessorMetadataDictionary instance, as described above.
- Check if the AttachedPicture field is stored with the file calling the Contains(Object) method. Another option is to iterate through the Keys collection until you find a key of this type.
- Read the value of the AttachedPicture field into the variable of the Bitmap type.
Visual Basic
'Get attached picture
Private Sub GetPicture(ByVal metadata As MediaProcessorMetadataDictionary)
'Check if picture is present
If metadata.Contains(MediaProcessorMetadataDictionary.AttachedPicture) Then
Dim picture As Aurigma.GraphicsMill.Bitmap = CType(metadata _
(MediaProcessorMetadataDictionary.AttachedPicture), _
Aurigma.GraphicsMill.Bitmap)
'Process picture
'...
Return
End If
MessageBox.Show("Picture is absent", "Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
End Sub
C#
//Get attached picture
private void GetPicture(MediaProcessorMetadataDictionary metadata)
{
//Check if picture is present
if (metadata.Contains(MediaProcessorMetadataDictionary.AttachedPicture))
{
Aurigma.GraphicsMill.Bitmap picture = (Aurigma.GraphicsMill.Bitmap)
metadata[MediaProcessorMetadataDictionary.AttachedPicture];
//Process picture
//...
return;
}
MessageBox.Show("Picture is absent", "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
See Also
Samples
Reference
- QTReader Class
- WMReader Class
- MediaProcessorMetadataDictionary Class
- QTReader.Metadata Property
- WMReader.Metadata Property
- MediaProcessorMetadataDictionary Members
- Contains(Object) Method
- Keys Property
- SynchronizedLyrics
- GetKeyDescription(Object) Method
- ID3SynchronisedLyrics Class
- TimestampFormat Property
- AttachedPicture
- Aurigma.GraphicsMill.Bitmap Class