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:
Let us look at them one by one.
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.
Media Processor Add-on allows reading of additional data only for files that are opened with QTReader or WMReader.
These readers support different sets of fields, and some fields that can be read by one of them, cannot be read by another.
In order to read simple text metadata, do the following:
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.
'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
//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());
}
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.
This field is currently supported only by WMReader.
In order to read synchronized lyrics, do the following:
'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
//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);
}
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 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
//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);
}