Copyright © 2001-2010 MultiMedia Soft

How to retrieve TAG information

Previous pageReturn to chapter overviewNext page

Many formats add some information, also known as Tags, to the song binary in order to allow an immediate identification of the file contents: the availability of this information and its contents can be retrieved using the following methods:

 

IsTagAvailable determines if a certain type of tag is contained inside the song binary

GetMp3TagVersion obtains the tag version for a MP3 song

GetFileTagField retrieves a specific field inside the tag

GetTagString retrieves a string inside the tag

 

Note that, in order to speed up the sound file loading, tag information is not available immediately after the call of the LoadSound method: once the sound is loaded, you can force the control to read tag information using the ReadSoundInfo method.

 

If the GetFileTagField method succeeds in retrieving the artist name and the title of the song, you can try requesting the related lyrics text through the SoundLyricsRequest method: this request will try to connect to the MultiMedia Soft server in order to check for availability of the requested lyrics text: when the request has been completed and after receiving the SoundLyricsAvailable event with a positive result, you can retrieve the lyrics text through the SoundLyricsGet method.

 

In a similar way, after having obtained information about the artist name and the title of the album, there is the possibility to obtain the cover art of the related Audio CD (see the How to get Audio CD info using CDDB servers and Amazon catalogue tutorial for details) and then to directly navigate to the purchase page of the specific Audio CD on the Amazon store through the CdNavigateToPurchasePage method.

 

If dealing with playlists, you can use the PlayListGetItemString method in order to receive a string containing the needed information.

 

Usually tags are internally implemented as concatenated strings: the only exception is the ID3V2 tag format used by MP3 songs: this format is far more complex because allows the use of binary data. Specifications about this tag format can be found on the ID3V2 official web site.

Due to the ID3V2 format complexity, our control will give the possibility to retrieve the full tag binary content but will not give information about the single elements inside the tag; for this purpose we have implemented the following methods:

 

GetMp3Tag2Size retrieves the size of the ID3V2 tag for a MP3 sound

GetMp3Tag2Data retrieves the full binary contents of the ID3V2 tag for a MP3 sound

 

Note that the GetMp3Tag2Data needs to receive from its container a memory buffer that will be filled with the tag binary: the buffer allocation is responsibility of the container which can obtain the buffer size calling the GetMp3Tag2Size.

Below you can find a couple of samples that demonstrate how to retrieve a ID3V2 tag in Visual Basic 6 and Visual C++ 6:

 

Visual Basic 6

 

Private Sub Command1_Click()

 Amp3dj1.LoadSound 0, "mysong.mp3"

 Amp3dj1.ReadSoundInfo 0

 If Amp3dj1.IsTagAvailable(0, TAGTYPE_ID3V2) = 0 Then

     Amp3dj1.CloseSound (0)

     Exit Sub

 End If

 

 Dim ntagSize As Long

 ntagSize = Mp3play1.GetMp3Tag2Size(0)

 

 Dim pBuffer() As Byte

 ReDim pBuffer(ntagSize)

 Amp3dj1.GetMp3Tag2Data 0, pBuffer, ntagSize

 

     ...

     use of the tag contents

     ...

 

End Sub

 

 

Visual C++ 6 with MFC

 

void CReadId3v2Dlg::OnButton1()

{

 m_player.LoadSound (0, "mysound.mp3");

 m_player.ReadSoundInfo (0);

 if (m_player.IsTagAvailable (0, TAGTYPE_ID3V2) == 0)

 {

     m_player.CloseSound (0);

     return;

 }

 

 long nTagSize = m_player.GetMp3Tag2Size (0);

 if (nTagSize == 0)

 {

     m_player.CloseSound (0);

     return;

 }

 

 BYTE *pTagBuffer = new BYTE[nTagSize];

 

 COleVariant var;

 var.vt = VT_BYREF | VT_UI1;

 var.pbVal = pTagBuffer;

 m_player.GetMp3Tag2Data (0, var, nTagSize);

 

     ...

     use of the tag contents

     ...

 

 delete pTagBuffer;

}

 

 

A sample of access to tag information in Visual Basic 6 and Visual C++ 6 can be found inside the following sample installed with the product's setup package:

- SoundInfo