I'm trying to read ID3v1 tags from mp3 files using "BASS.dll"(via bass.lib and bass.h).
It works fine until .mp3 file has title (or artist) has 30 characters.
Instead
Happy Times (Feat. Margaux Bos
I get Happy Times (Feat. Margaux BosEmigrate
with Emigrate added (that's artist tag).
How to make it work properly, without adding artist tag?
Here is my source code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "bass.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
BASS_Init(-1, 44000, 0, 0, 0);
if(OpenDialog1->Execute())
{
HSTREAM stream = BASS_StreamCreateFile(false, OpenDialog1->FileName.c_str(), 0, 0, 0);
TAG_ID3 *tags = (TAG_ID3*)BASS_ChannelGetTags(stream, BASS_TAG_ID3);
Edit1->Text = tags->title;
}
}
The text fields of the
TAG_ID3struct are not guaranteed to be null terminated, but your code is treating them as if they are, so it ends up reading into the next field when a null terminator is not present. To fix that, you have to take their max lengths into account, eg:Or:
Same with all of other text fields:
id: 3 charstitle: 30 charsartist: 30 charsalbum: 30 charsyear: 4 charscomment: 30 charsYou can use a simple template wrapper to help you:
Note that the
commentfield has an additional caveat to watch out for: