How to read TAG information in sound files |
|
The majority of audio formats allows the insertion of metadata, also known as "tags", which helps describing the content of the audio file by inserting information such as the title, artist, album, track number and other information about the audio file to be stored in the file itself.
The TagsReaderMan class of Audio Dj Studio API for .NET allows reading the most common tag formats (in case you should need both reading and writing you may consider using our Audio Sound Editor API for .NET component): this can be accomplished by analyzing the audio file loaded inside an editing session, through the TagsReader.ALL_AnalyzeSoundOnPlayer method, or by accessing a sound file directly on the local disk through the TagsReader.ALL_AnalyzeSoundFile method.
Both methods return a combination of flags which allow determining the specific tag formats embedded inside the audio file; certain audio formats allow embedding more than one tag format; for example, the MP3 format could contain ID3V1, ID3V2 and LYRICS3 formats: the combination of flags allows discriminating which of them are effectively available inside the audio file and to manage them separately; if the returned value should be 0, this would mean that no known tag format is embedded inside the audio file. A small example can be see inside the following code snippets:
Visual Basic .NET |
' perform tags analysis Dim nTagFormat As enumTagAvailable = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(0) If nTagFormat = enumTagAvailable.TAG_FLAG_NONE Then ' no tag detected Return End If
' check tags availability: we use bitwise operators because more than one type of tag format could be available If (nTagFormat And enumTagAvailable.TAG_FLAG_ID3V1) <> 0 Then ... do something with ID3V1 ... End If If (nTagFormat And enumTagAvailable.TAG_FLAG_ID3V2) <> 0 Then ... do something with ID3V2 ... End If If (nTagFormat And enumTagAvailable.TAG_FLAG_WMA) <> 0 Then ... do something with WMA ... End If If (nTagFormat And enumTagAvailable.TAG_FLAG_MP4) <> 0 Then ... do something with MP4 ... End If
|
Visual C# |
// perform tags analysis enumTagAvailable nTagFormat = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(0); if (nTagFormat == enumTagAvailable.TAG_FLAG_NONE) // no tag detected return;
// check tags availability: we use bitwise operators because more than one type of tag format could be available if ((nTagFormat & enumTagAvailable.TAG_FLAG_ID3V1) != 0) { ... do something with ID3V1 ... } if ((nTagFormat & enumTagAvailable.TAG_FLAG_ID3V2) != 0) { ... do something with ID3V2 ... } if ((nTagFormat & enumTagAvailable.TAG_FLAG_WMA) != 0) { ... do something with WMA ... } if ((nTagFormat & enumTagAvailable.TAG_FLAG_MP4) != 0) { ... do something with MP4 ... }
|
Some of the tag fields, such as artist, title and album, are common to all of the tag formats so Audio Dj Studio API for .NET exposes a set of methods that allows accessing these common frames without the need to know the specific format of the audio file being edited: TagsReader.ALL_CommonFrameGet method allows reading these common frames.
IMPORTANT NOTE:When using the TagsReader.ALL_AnalyzeSoundOnPlayer and TagsReader.ALL_AnalyzeSoundFile methods, subsequent calls to other methods of the TagsReaderMan class will be related to that specific analysis. If for example you have an instance of Audio DJ Studio with 2 players, named Player_A and Player_B respectively and you want to obtain the title of the loaded song, after the following call
Dim nTagFormat As enumTagAvailable = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(Player_A) Dim strTitle as String = audioDjStudio1.TagsReader.ALL_CommonFrameGet (TAG_FIELD_TITLE)
the returned title will be about the sound file loaded inside Player_A while after the following call
nTagFormat = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(Player_B) strTitle = audioDjStudio1.TagsReader.ALL_CommonFrameGet (TAG_FIELD_TITLE)
the returned title will be about the sound file loaded inside Player_B. This means that, in order to read further information about tags stored inside Player_A, for example the author's name, you will have to perform a new analysis of the sound loaded in Player_A as seen below:
nTagFormat = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(Player_A) Dim strAuthor as String = audioDjStudio1.TagsReader.ALL_CommonFrameGet (TAG_FIELD_ARTIST)
|
When dealing with specific audio formats, Audio Dj Studio API for .NET allows editing the following kind of tags:
• | WMA |
• | MP4 |
• | APE |
• | FLAC |
The ID3V1 tag, intended for usage with MP3 files, occupies 128 bytes beginning with the string TAG and is placed at the end of the file. This tag allows 30 bytes each for the title, artist, album, and a "comment", four bytes for the year, and a byte to identify the genre of the song from a predefined list of 80 values (Winamp later extended this list to 148 values).
One improvement to ID3V1 uses the last two bytes of the comment field to store the track number. Such tags are referred to as ID3V1.1.
A full description of this tagging format can be found on this link.
You can know if the ID3V1 tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_ID3V1 this would mean that the ID3V1 tag is available.
ID3V1 fields can be read through the TagsReader.ID3V1_FieldGet method.
ID3V2 is a tagging system that lets you put enriching and relevant information about your audio files within them. ID3V2 is a chunk of data prepended to the binary audio data. Each ID3V2 tag holds one or more smaller chunks of information, called frames. These frames can contain any kind of information and data you could think of such as title, album, performer, website, lyrics, equalizer presets, pictures etc.
A full description of this tagging format can be found on this link.
Audio Dj Studio API for .NET supports 3 different versions of ID3V2:
• | ID3V2.2 |
• | ID3V2.3 |
• | ID3V2.4 |
All of them are currently supported in read mode only. This system allows the use of UNICODE characters in UTF-16 format and, when dealing with version ID3V2.4, in UTF-8 format as well.
You can know if the ID3V2 tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_ID3V2 this would mean that the ID3V2 tag is available.
The list of supported ID3V2 frames, with related identifiers and methods to access stored information, can be found on the table below:
Supported frame types |
Frame identifiers |
Multiple |
Related methods |
Text-based frames |
TIT1, TIT2, TIT3, TALB, TOAL, TRCK, TPOS, TSST, TSRC, TPE1, TPE2, TPE3, TPE4, TOPE, TEXT, TOLY, TCOM, TMCL, TIPL, TENC, TBPM, TLEN, TKEY, TLAN, TCON, TFLT, TMED, TMOO, TCOP, TPRO, TPUB, TOWN, TRSN, TRSO, TOFN, TDLY, TDEN, TDOR, TDRC, TDRL, TDTG, TSSE, TSOA, TSOP, TSOT |
No |
|
User text frames |
TXXX |
Yes |
|
URL-based frames |
WCOM, WCOP, WOAF, WOAR, WOAS, WORS, WPAY, WPUB |
No |
|
User URL frames |
WXXX |
Yes |
|
Comment frames |
COMM |
Yes |
|
Commercial frames |
COMR |
Yes |
TagsReader.ID3V2_CommercialFrameInfoGet TagsReader.ID3V2_CommercialFramePictureBitmapGet TagsReader.ID3V2_CommercialFramePictureFileGet TagsReader.ID3V2_CommercialFramePictureMemoryFileGet |
Event timings (cue points) frame |
ETCO |
No |
|
General objects frames |
GEOB |
Yes |
TagsReader.ID3V2_GeneralObjectFrameFileGet TagsReader.ID3V2_GeneralObjectFrameInfoGet |
Music CD identifier frames |
MCDI |
No |
|
Ownership frame |
OWNE |
No |
|
Picture frames |
APIC |
Yes |
TagsReader.ID3V2_PictureFrameBitmapGet TagsReader.ID3V2_PictureFrameFileGet TagsReader.ID3V2_PictureFrameInfoGet TagsReader.ID3V2_PictureFrameMemoryFileGet |
Play counter frame |
PCNT |
No |
|
Popularimiter frame |
POPM |
Yes |
TagsReader.ID3V2_PopularimeterFrameCounterGet |
Private frame |
PRIV |
Yes |
TagsReader.ID3V2_PrivateFrameFileGet TagsReader.ID3V2_PrivateFrameMemoryFileGet |
Synchronized lyrics frames |
SYLT |
Yes |
TagsReader.ID3V2_SynchLyricsFrameGet |
Terms of use frames |
USER |
Yes |
|
Unsynchronized lyrics frames |
USLT |
Yes |
Support for other frames not available in the list above may be added in future versions of the component so, in case you should need the support of a specific frame, feel free to contact our technical support team.
The "Multiple" column specifies if more than one frame, having the same identifier, can be available inside the tag; in order to know how many frames are available for a specific identifier, you should use the ID3V2_FrameCountGet method. If for example you should need enumerating pictures stored inside the tag, you could do something similar:
Visual Basic .NET |
' perform tags analysis Dim nTagFormat As enumTagAvailable nTagFormat = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(0) If nTagFormat And TAG_FLAG_ID3V2 Then ' check the availability of embedded pictures through the search of "APIC" frames Dim nAvailablePictures as Int32 nAvailablePictures = audioDjStudio1.TagsReader.ID3V2_FrameCountGet("APIC")
' output each picture's description Dim nIndex as Int32 = 0 Do While nIndex < nAvailablePictures Debug.Print audioDjStudio1.TagsReader.ID3V2_PictureFrameInfoGet (nIndex, enumId3v2FrameInfo.ID3V2_FRAME_INFO_DESCRIPTION) nIndex += 1 Loop End If
|
Visual C# |
// perform tags analysis enumTagAvailable nTagFormat = audioDjStudio1.TagsReader.ALL_AnalyzeSoundOnPlayer(0); if ((nTagFormat & enumTagAvailable.TAG_FLAG_ID3V2) != 0) { // check the availability of embedded pictures through the search of "APIC" frames int nAvailablePictures = audioDjStudio1.TagsReader.ID3V2_FrameCountGet("APIC");
// output each picture's description for (int nIndex = 0; nIndex < nAvailablePictures; nIndex++) Console.WriteLine (audioDjStudio1.TagsReader.ID3V2_PictureFrameInfoGet (nIndex, enumId3v2FrameInfo.ID3V2_FRAME_INFO_DESCRIPTION)); }
|
Identifiers of frames available inside the ID3V2 tag can be enumerated using the combination of the TagsReader.ID3V2_UniqueFramesCountGet and TagsReader.ID3V2_UniqueFramesIdGet methods.
The Lyrics3 v2.00 tag resides between the audio and the ID3V1 tag, which must be present. The tag uses only text for everything from content to size descriptors, which are represented as numerical strings.
A full description of this tagging format can be found on this link.
You can know if the Lyrics3 tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_LYRICS3 this would mean that the Lyrics3 tag is available.
Text fields of the Lyrics3 tag can be read through the TagsReader.LYRICS3_TextFieldGet method.
The lyrics text can be read through the TagsReader.LYRICS3_LyricsGet method.
The link to the image field can be read through the TagsReader.LYRICS3_ImageLinkGet method.
You can know if the WMA tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WMA this would mean that the WMA tag is available.
The list of supported WMA frames, with related identifiers and methods to access stored information, can be found on the table below:
Supported frame types |
Frame identifiers |
Multiple |
Related methods |
Text-based frames |
You can use predefined identifiers or, in alternative, your own custom ones: a list of predefined identifiers can be found inside the Windows Media Format SDK. |
No |
|
Picture frames |
WM/Picture |
Yes |
TagsReader.WMA_PictureFrameBitmapGet TagsReader.WMA_PictureFrameCountGet TagsReader.WMA_PictureFrameFileGet TagsReader.WMA_PictureFrameInfoGet TagsReader.WMA_PictureFrameMemoryFileGet |
The "Multiple" column specifies that there may be more than one picture frame available inside the tag; you can know how many picture frames are available through the TagsReader.WMA_PictureFrameCountGet method.
Identifiers of frames available inside the WMA tag can be enumerated using the combination of the TagsReader.WMA_UniqueFramesCountGet and TagsReader.WMA_UniqueFramesIdGet methods.
Vorbis metadata, called Vorbis comments, supports metadata tags similar to those implemented in the ID3 standard for MP3. All strings are encoded as UTF-8. Music tags are typically implemented as strings of the form "[TAG]=[VALUE]", for instance, "ARTIST=The big band". The tags are case-insensitive, thus typing "ARTIST=The big band" would be the same as "artist=The big band".
You can know if the OGG Vorbis tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_OGG this would mean that the OGG Vorbis tag is available.
Predefined text frames can be read through the TagsReader.OGG_TextFrameGet method.
User defined text frames can be read through the TagsReader.OGG_UserFrameGet method.
Identifiers of frames available inside the OGG tag can be enumerated using the combination of the TagsReader.OGG_UniqueFramesCountGet and TagsReader.OGG_UniqueFramesIdGet methods.
There is no official MPEG standard on how to embed metadata tags in MP4 files. Apple iTunes therefore started to use their own solution in order to be able to store metadata tags. Those iTunes tags quickly became the de-facto standard for metadata tags within MP4 files. Metadata tags within MP4 files are stored within so-called "boxes" (also known as "atoms").
You can know if the MP4 tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_MP4 this would mean that the MP4 tag is available.
The list of supported MP4 frames, with related identifiers and methods to access stored information, can be found on the table below:
Supported frame types |
Frame identifiers |
Multiple |
Related methods |
Text-based frames |
©alb, ©ART, ©aut, aART, tmpo, catg, dsk, disk, ©cmt, ©wrt, cpil, ©day, ©cpy, ©day, ©des, ©inf, ©dir, ©dis, ©too, ©grp, keyw, ©lyr, ©nam, ©url, ©ope, ©fmt, ©src, ©prf, rate, ©prd, ©wrn |
No |
|
Picture frames |
|
Yes |
TagsReader.MP4_PictureFrameBitmapGet TagsReader.MP4_PictureFrameCountGet TagsReader.MP4_PictureFrameFileGet TagsReader.MP4_PictureFrameMemoryFileGet |
The "Multiple" column specifies that there may be more than one picture frame available inside the tag; you can know how many picture frames are available through the TagsReader.MP4_PictureFrameCountGet method.
Identifiers of frames available inside the WMA tag can be enumerated using the combination of the TagsReader.MP4_UniqueFramesCountGet and TagsReader.MP4_UniqueFramesIdGet methods.
APE tags are closer to Vorbis comments than ID3 tags. Like Vorbis comments, they are unstructured key/value pairs.
You can know if the APE tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_APE this would mean that the APE tag is available.
Predefined text frames can be read through the TagsReader.APE_TextFieldGet method.
User defined text frames can be read through the TagsReader.APE_UserFieldGet method.
Identifiers of frames available inside the APE tag can be enumerated using the combination of the TagsReader.APE_UniqueFramesCountGet and TagsReader.APE_UniqueFramesIdGet methods.
FLAC has it's own native tagging system which is mostly identical to that of OGG Vorbis described above, indeed they are sometime called alternately "FLAC tags" and "Vorbis comments". Respect to the Vorbis tagging system, FLAC allows embedding pictures as well as seen for the ID3V2, WMA and MP4 formats.
You can know if the FLAC tag is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_FLAC this would mean that the FLAC tag is available.
The list of supported FLAC frames can be found on the table below:
Supported frame types |
Multiple |
Related methods |
Text-based frames |
No |
|
Picture frames |
Yes |
TagsReader.FLAC_PictureFrameBitmapGet TagsReader.FLAC_PictureFrameCountGet TagsReader.FLAC_PictureFrameFileGet TagsReader.FLAC_PictureFrameInfoGet TagsReader.FLAC_PictureFrameMemoryFileGet |
The "Multiple" column specifies that there may be more than one picture frame available inside the tag; you can know how many picture frames are available through the TagsReader.FLAC_PictureFrameCountGet method.
Identifiers of frames available inside the FLAC tag can be enumerated using the combination of the TagsReader.FLAC_UniqueFramesCountGet and TagsReader.FLAC_UniqueFramesIdGet methods.
WAV files are based upon the RIFF format which consists entirely of "chunks"; some of these chunks allows storing metadata; Audio Dj Studio API for .NET supports reading the following types of chunks:
• | CART |
• | BEXT |
• | DISP |
You can know if any of the chunks above are available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the combination of any of the following flags, this would mean that the chunks are available: TAG_FLAG_WAV_CART, TAG_FLAG_WAV_BEXT, TAG_FLAG_WAV_DISP and TAG_FLAG_WAV_LIST_INFO.
The CART chunk contains fields and attributes that a large number of broadcast systems use to describe an audio file. Its full specifications can be found inside the CartChunk.org web site.
You can know if the CART chunk is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_CART this would mean that the CART chunk is available.
Text fields can be read through the TagsReader.WAV_CartChunkTextFieldGet method.
Time markers can be read through the TagsReader.WAV_CartChunkTimeMarkerFieldGet method.
The BEXT chunk (Broadcast Audio Extension) adds to the RIFF format extra parameters needed for the exchange of material between broadcasters.
You can know if the BEXT chunk is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_BEXT this would mean that the BEXT chunk is available.
Text fields can be read through the TagsReader.WAV_BextChunkTextFieldGet method.
Binary fields can be read through the TagsReader.WAV_BextChunkBinaryFieldGet method.
The DISP chunk allows entering a text string to display on the user interface when the WAV file is loaded.
You can know if the DISP chunk is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_DISP this would mean that the DISP chunk is available.
The text field can be read through the TagsReader.WAV_DisplayChunkTextGet method.
The LIST chunk can contain a list of frames (sub-chunks) of type INFO, each of them containing a different text string. As for other kinds of chunks, each INFO frame is defined by a four characters identifier (FOURCC). Some identifier has already been standardized by the EXIF 2.3 specification (for esample 'IART' for 'Artist', 'ICMT' for 'Comments' or 'ICOP' for 'Copyright'), but the user may create new custom ones.
You can know if the LIST INFO chunk is available by checking the value returned by the TagsReader.ALL_AnalyzeSoundOnPlayer or TagsReader.ALL_AnalyzeSoundFile methods: if it should contain the flag TAG_FLAG_WAV_LIST_INFO this would mean that the LIST INFO chunk is available.
Identifiers of INFO frames available inside the LIST chunk can be enumerated using the combination of the TagsReader.WAV_ListInfoChunkUniqueFramesCountGet and TagsReader.WAV_ListInfoChunkUniqueFramesIdGet methods.
Single INFO frames can be read through the TagsReader.WAV_ListInfoChunkFrameGet method.
Samples of usage of tags editing through the TagsReader object in Visual C# and Visual Basic.NET can be found inside the following samples installed with the product's setup package:
- TagsReader