主题:mp3 ID3 读取
mp3的id3信息存放在mp3文件结尾处的128字节处,结构如下:
type ID3struct =packed record
ID:array[0..2] of char
title :array[0..29] of char;
artist:array[0..29] of char;
album:array[0..29} of char;
year:array[0..3] of char;
comment:array[0..29] of char;
genre:byte;
用指针读出相应位置的数据,就可以读出ID3信息:
program showID3;
{$apptype console}
var
tempfile:file of byte; //tempfile指针,二进制型文件
i:integer;
x:byte;
begin
assign(tempfile,'1.mp3');
reset(tempfile);//文件关联,复位
seek(tempfile,(filesize(tempfile)-128)); //指针指向距文件结尾128字节处
writeln('ID:');
for i:=0 to 2 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('title:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('artist:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('album:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('year:');
for i:=0 to 3 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('comment:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln; //用循环的方法依次读出各个字节
close(tempfile);
end.
type ID3struct =packed record
ID:array[0..2] of char
title :array[0..29] of char;
artist:array[0..29] of char;
album:array[0..29} of char;
year:array[0..3] of char;
comment:array[0..29] of char;
genre:byte;
用指针读出相应位置的数据,就可以读出ID3信息:
program showID3;
{$apptype console}
var
tempfile:file of byte; //tempfile指针,二进制型文件
i:integer;
x:byte;
begin
assign(tempfile,'1.mp3');
reset(tempfile);//文件关联,复位
seek(tempfile,(filesize(tempfile)-128)); //指针指向距文件结尾128字节处
writeln('ID:');
for i:=0 to 2 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('title:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('artist:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('album:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('year:');
for i:=0 to 3 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln;
writeln('comment:');
for i:=0 to 29 do
begin
read(tempfile,x);
write(chr(x));
end;
writeln; //用循环的方法依次读出各个字节
close(tempfile);
end.