Thema: Delphi Probleme mit Strings

Einzelnen Beitrag anzeigen

boserPascal

Registriert seit: 4. Apr 2006
96 Beiträge
 
Delphi 5 Professional
 
#5

Re: Probleme mit Strings

  Alt 18. Jul 2006, 22:57
Das hier ist der Quelltext, die unrelevanten Prozeduren hab ich rausgenommen (also die die keinen Einfluß haben).
der code ist Fett

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, CheckLst, ExtCtrls, Buttons, Menus;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    CheckListBox1: TCheckListBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    BitBtn3: TBitBtn;
    BitBtn6: TBitBtn;
    BitBtn7: TBitBtn;
    BitBtn8: TBitBtn;
    ListBox1: TListBox;
    PopupMenu1: TPopupMenu;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure BitBtn4Click(Sender: TObject);
    procedure BitBtn5Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn8Click(Sender: TObject);
    procedure BitBtn6Click(Sender: TObject);
    procedure BitBtn7Click(Sender: TObject);
    procedure Lese_ID3Tag(Filename: string);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

Type
  TID3Tag = record
    ID: string;
    Titel: string;
    Artist: string;
    Album: string;
    Year: string;
    Comment: string;
    Genre: byte;
    dauer: longint; //in sekunden;
    sample: integer;
    bits: byte;
    vers: byte;
    layers: byte;
end;

const
  MPEG_BIT_RATES : array[1..3] of array[1..3] of array[0..15] of word =
  { Version 1, Layer I }
    (((0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0),
  { Version 1, Layer II }
    (0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0),
  { Version 1, Layer III }
    (0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0)),
  { Version 2, Layer I }
    ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0),
  { Version 2, Layer II }
    (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0),
  { Version 2, Layer III }
    (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)),
  { Version 2.5, Layer I }
    ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0),
  { Version 2.5, Layer II }
    (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0),
  { Version 2.5, Layer III }
    (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)));
  sample_rates: array[1..3] of array [0..3] of word=((44100,48000,32000,0),(22050,24000,16000,0),(11025,12000,8000,0));

var
  Form1: TForm1;
  ID3Tag: TID3Tag;

implementation

{$R *.DFM}

procedure TForm1.BitBtn4Click(Sender: TObject);
var Datei: file of char;
    Zeile,Temp : string;
    Buffer: char;
begin
     if OpenDialog1.Execute then
     begin
          AssignFile(Datei, OpenDialog1.filename);
          Reset(Datei);
          Zeile:='';
          while not eof(Datei) do
          begin
               Read(Datei, Buffer);
               if Buffer = #$0D then
               begin
                    ListBox1.Items.Add(Zeile);
                    Lese_ID3Tag(Zeile);
                    if ID3Tag.ID = 'TAGthen
                    begin
                         with ID3Tag do
                              [b]Temp:=Artist+' - '+Album+' - '+Titel;[/b]//schreibt nur artist raus
                         showmessage(id3tag.Album); //nur zum testen ob er die Strings eventuell doch ausgibt
                         CheckListBox1.Items.Add(Temp);
                    end
                    else
                        CheckListBox1.Items.Add(Zeile);
                    Zeile:='';
               end
               else
                   if Buffer >= #$20 then
                      Zeile:=Zeile+Buffer;
          end;
          CloseFile(Datei);
     end;
     caption:='Playlist - '+OpenDialog1.filename;
end;

procedure TForm1.Lese_ID3Tag(Filename: string);
var
   Buffer: array[1..128] of char;
   Datei: File;
   mp3hdrread: array[1..4] of byte;
   mp3hdr: longint absolute mp3hdrread;
   tempbyte, bitrateindex, versionindex: byte;
   bitrate, version, layer, groese: longint;
begin
     try
        AssignFile(Datei, Filename);
        Reset(Datei,1);
        groese:=filesize(Datei);
        blockread(Datei,mp3hdrread,4);
        tempbyte:=mp3hdrread[1];
        mp3hdrread[1]:=mp3hdrread[4];
        mp3hdrread[4]:=tempbyte;
        tempbyte:=mp3hdrread[2];
        mp3hdrread[2]:=mp3hdrread[3];
        mp3hdrread[3]:=tempbyte;
        reset(Datei,1);
        Seek(Datei,FileSize(Datei)-128);
        BlockRead(Datei, Buffer, SizeOf(Buffer));
        CloseFile(Datei);
        bitrateindex:=((mp3hdr shr 12) and $F);
        versionindex:=((mp3hdr shr 19) and $3);
        case versionindex of
             0: version:=3;
             1: version:=0; //unbekannt
             2: version:=2;
             3: version:=1;
        end;
        layer:=4-((mp3hdr shr 17) and $3);
        if version<>0 then
           bitrate:=MPEG_BIT_RATES[version][layer][bitrateindex]
        else
            bitrate:=128;
        with ID3Tag do
        begin
             ID:=copy(Buffer,1,3);
             Titel:=copy(Buffer,4,30);
             Artist:=copy(Buffer,34,30);
             Album:=copy(Buffer,64,30);
             Year:=copy(Buffer,94,4);
             Comment:=copy(Buffer,98,30);
             Genre:=ord(Buffer[128]);
             sample:=sample_rates[version][((mp3hdr shr 10) and $3)];
             dauer:=(groese*8) div ((bitrate)*1000);
             bits:=bitrate;
             vers:=version;
             layers:=layer;
        end;
     except
     end;
end;

end.
Stefan
  Mit Zitat antworten Zitat