Jump to content

Delphi: ID3 tag over 30 characters is cut off


Recommended Posts

This code:

type
TID3Tag = record
ID: string[3];
Titel: string[30];
Artist: string[30];
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function readID3Tag(FileName: string): TID3Tag;
var
FS: TFileStream;
Buffer: array [1..128] of Char;
begin
FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
FS.Seek(-128, soFromEnd);
FS.Read(Buffer, 128);
with Result do
begin
ID := Copy(Buffer, 1, 3);
Titel := Copy(Buffer, 4, 30);
Artist := Copy(Buffer, 34, 30);
end;
finally
FS.Free;
end;
end;

procedure TfrmMain.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
with readID3Tag(OpenDialog1.FileName) do
begin
LlbID.Caption := 'ID: ' + ID;
LlbTitel.Caption := 'Titel: ' + Titel;
LlbArtist.Caption := 'Artist: ' + Artist;
end;
end;
end;

From here extracts the song and artist tags correctly, however if either is over 30 characters the rest of the artist or song tag is chopped off... An example I'm looking at now is "Glamorous Indie Rock & Roll [2004]" as a ID3 song tag. It comes out as "Glamorous Indie Rock _Roll [2". Does anyone know how I could make this work correctly?

Edited by BrainDrain
Link to comment
Share on other sites


...with a little use of the Brain?

Titel: string[30];

Artist: string[30];

end;

var

Form1: TForm1;

implementation

{$R *.dfm}

function readID3Tag(FileName: string): TID3Tag;

var

FS: TFileStream;

Buffer: array [1..128] of Char;

begin

FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);

try

FS.Seek(-128, soFromEnd);

FS.Read(Buffer, 128);

with Result do

begin

ID := Copy(Buffer, 1, 3);

Titel := Copy(Buffer, 4, 30);

Artist := Copy(Buffer, 34, 30);

...and I don't even know much about Delphi.
Link to comment
Share on other sites

Thank goodness he got banned :P. I got a reply via PM from someone here that helped a lot.

EDIT: The ID3 version 1 tags are up against each other... e.g. [artistdata...................songdata...................]

Using his method, setting the number of chars to recieve to 35 for the artist name would give [artistdata.................songd]

His method is one of the first I tried.

Edited by BrainDrain
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...