Die Mp3 Dateien werden zwar korrekt ausgelesen, aber bei WMA-Dateien wird in die Listbox ein Strich hinzugefügt, statt Artist - Titel. AddFiles ruft für die Items ReadID3Tag (ich weiß, der Titel der Prozedur passt nicht mehr) auf und ReadId3Tag entscheidet weiter:
Delphi-Quellcode:
TID3Tag = record
// MP3
ID: Array[0..3] of Char;
Titel: Array[0..30] of Char;
Artist: Array[0..30] of Char;
Album: Array[0..30] of Char;
Year: Array[0..4] of Char;
Comment: Array[0..30] of Char;
Genre: Byte;
Filename: String;
Endung: String;
// WMA
FValid: Boolean;
FFileSize: Integer;
FChannelModeID: Byte;
FSampleRate: Integer;
FDuration: Double;
FBitRate: Integer;
FTitle: WideString;
FArtist: WideString;
FAlbum: WideString;
FTrack: Integer;
FYear: WideString;
FGenre: WideString;
FComment: WideString;
end;
procedure TfrmMain.AddFiles(files : Array of String);
var
len : integer;
i : integer;
begin
len := Length(fFiles);
SetLength(fFiles, len + Length(files));
for i := 0 to high(files) do
begin
fFiles[len+i] := ReadID3Tag(files[i]);
end;
end;
procedure TfrmMain.xiAddClick(Sender: TObject);
var
i : Integer;
begin
if op1.Execute then
begin
setlength(f, op1.files.count);
for i := 0 to pred(op1.files.count) do
begin
f[i] := op1.files[i];
end;
AddFiles(f);
end;
end;
function TfrmMain.ReadID3Tag(const FileName: String): TID3Tag;
begin
if LowerCase(ExtractFileExt(Filename)) = '.mp3' then
begin
FillChar(Result, SizeOf(Result), 0);
with TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone) do
try
Position := Size - 128;
Read(Result.ID, 3);
Read(Result.Titel, 30);
Read(Result.Artist, 30);
Read(Result.Album, 30);
Read(Result.Year, 4);
Read(Result.Comment, 30);
Read(Result.Genre, 1);
Result.Filename := Filename;
Result.Endung := LowerCase(ExtractFileExt(Filename));
finally
Free;
end;
end;
if LowerCase(ExtractFileExt(Filename)) = '.wma' then
begin
if WMAfile.ReadFromFile(Filename) then
if WMAfile.Valid then
begin
Result.FTitle := WMAfile.Title;
Result.FArtist := WMAfile.Artist;
Result.Filename := Filename;
Result.Endung := LowerCase(ExtractFileExt(Filename));
finally
Free;
end;
end;
end;