| Autor |
Beitrag |
Hoellenwesen
      
Beiträge: 17
|
Verfasst: So 01.02.04 20:22
Hallo zusammen
ich hoffe mir kann jemand helfen. ich habe in einer ListBox eine menge mp3 drin, und wenn ich ein item markiere und dann nen rechtsklick mache öffnet sich ein neues formular. in diesem formular möchte ich dann den ID3-Tag des ausgewählten items angezeigt bekommen.
da das geschriebene hier ziemlich verwirrend ist, poste ich euch mal den code den ich benutze:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238:
| unit titelinfo;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm8 = class(TForm) GroupBox1: TGroupBox; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; EdtTitle: TEdit; EdtArtist: TEdit; EdtAlbum: TEdit; EdtYear: TEdit; EdtComment: TEdit; EdtTrack: TEdit; CbGenre: TComboBox; Button1: TButton; Button2: TButton; Button3: TButton; procedure FormCreate(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private procedure WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); message WM_GETMINMAXINFO; public end;
var Form8: TForm8;
implementation
uses playlist;
{$R *.dfm}
const Genres: array[0..147] of string = ('Blues', 'Classic Rock', 'Country', 'Dance', 'Disco', 'Funk', 'Grunge', 'Hip-Hop', 'Jazz', 'Metal', 'New Age', 'Oldies', 'Other', 'Pop', 'R&B', 'Rap', 'Reggae', 'Rock', 'Techno', 'Industrial', 'Alternative', 'Ska', 'Death Metal', 'Pranks', 'Soundtrack', 'Euro-Techno', 'Ambient', 'Trip-Hop', 'Vocal', 'Jazz+Funk', 'Fusion', 'Trance', 'Classical', 'Instrumental', 'Acid', 'House', 'Game', 'Sound Clip', 'Gospel', 'Noise', 'AlternRock', 'Bass', 'Soul', 'Punk', 'Space', 'Meditative', 'Instrumental Pop', 'Instrumental Rock', 'Ethnic', 'Gothic', 'Darkwave', 'Techno-Industrial', 'Electronic', 'Pop-Folk', 'Eurodance', 'Dream', 'Southern Rock', 'Comedy', 'Cult', 'Gangsta', 'Top 40', 'Christian Rap', 'Pop/Funk', 'Jungle', 'Native American', 'Cabaret', 'New Wave', 'Psychadelic', 'Rave', 'Showtunes', 'Trailer', 'Lo-Fi', 'Tribal', 'Acid Punk', 'Acid Jazz', 'Polka', 'Retro', 'Musical', 'Rock & Roll', 'Hard Rock', 'Folk', 'Folk-Rock', 'National Folk', 'Swing', 'Fast Fusion', 'Bebob', 'Latin', 'Revival', 'Celtic', 'Bluegrass', 'Avantgarde', 'Gothic Rock', 'Progressive Rock', 'Psychedelic Rock', 'Symphonic Rock', 'Slow Rock', 'Big Band', 'Chorus', 'Easy Listening', 'Acoustic', 'Humour', 'Speech', 'Chanson', 'Opera', 'Chamber Music', 'Sonata', 'Symphony', 'Booty Bass', 'Primus', 'Porn Groove', 'Satire', 'Slow Jam', 'Club', 'Tango', 'Samba', 'Folklore', 'Ballad', 'Power Ballad', 'Rhythmic Soul', 'Freestyle', 'Duet', 'Punk Rock', 'Drum Solo', 'Acapella', 'Euro-House', 'Dance Hall', 'Goa', 'Drum & Bass', 'Club-House', 'Hardcore', 'Terror', 'Indie', 'BritPop', 'Negerpunk', 'Polsk Punk', 'Beat', 'Christian Gangsta Rap', 'Heavy Metal', 'Black Metal', 'Crossover', 'Contemporary Christian', 'Christian Rock', 'Merengue', 'Salsa', 'Trash Metal', 'Anime', 'Jpop', 'Synthpop');
type TID3Tag = record ID: array [0..2] of Char; Titel: 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..27] of Char; Dummy: Byte; Track: Byte; Genre: Byte; end;
function readID3Tag(FileName: string): TID3Tag; const id3TagSize = SizeOf(TID3Tag); var FS: TFileStream; begin FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); try FS.Seek(-id3TagSize, soFromEnd); FillChar(Result, id3TagSize, #0); FS.read(Result, id3TagSize); if AnsiUpperCase(Result.ID) <> 'TAG' then begin FillChar(Result, id3TagSize, #0); Result.Genre := 255; end; finally FS.Free; end; end;
procedure writeID3Tag(FileName: string; id3Tag: TID3Tag); const id3TagSize = SizeOf(TID3Tag); var FS: TFileStream; Buffer: array [0..2] of Char; begin FS := TFileStream.Create(FileName, fmOpenReadWrite or fmShareDenyWrite); try FS.Seek(-id3TagSize, soFromEnd); FS.read(Buffer, 3); if AnsiUpperCase(Buffer) = 'TAG' then FS.Seek(-id3TagSize, soFromEnd) else FS.Seek(0, soFromEnd); FS.WriteBuffer(id3Tag, id3TagSize); finally FS.Free; end; end;
procedure removeID3Tag(FileName: string); const id3TagSize = SizeOf(TID3Tag); var FS: TFileStream; Buffer: array [0..2] of Char; begin FS := TFileStream.Create(FileName, fmOpenReadWrite or fmShareDenyWrite); try FS.Seek(-id3TagSize, soFromEnd); FS.read(Buffer, 3); if AnsiUpperCase(Buffer) = 'TAG' then FS.Size := FS.Size - id3TagSize; finally FS.Free; end; end;
procedure TForm8.WMGetMinMaxInfo(var Msg: TWMGetMinMaxInfo); begin inherited; with Msg.MinMaxInfo^ do begin ptMinTrackSize.x := Form8.Width; ptMaxTrackSize.x := Form8.Width; ptMinTrackSize.y := Form8.Height; ptMaxTrackSize.y := Form8.Height; end; end;
procedure TForm8.FormCreate(Sender: TObject); var i: Integer; begin cbGenre.Style := csDropDownList; CbGenre.Items.Add(''); for i := Low(Genres) to High(Genres) do CbGenre.Items.Add(Genres[i]); EdtTitle.MaxLength := 30; EdtArtist.MaxLength := 30; EdtAlbum.MaxLength := 30; EdtYear.MaxLength := 4; EdtTrack.MaxLength := 3; EdtComment.MaxLength := 28; end;
procedure TForm8.Button3Click(Sender: TObject); var ID3Tag: TID3Tag; begin ID3Tag := readID3Tag(Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex]); EdtTitle.Text := Trim(ID3Tag.Titel); EdtArtist.Text := Trim(ID3Tag.Artist); EdtAlbum.Text := Trim(ID3Tag.Album); EdtYear.Text := Trim(ID3Tag.Year); EdtComment.Text := Trim(ID3Tag.Comment); if ID3Tag.Track <> 0 then EdtTrack.Text := IntToStr(ID3Tag.Track) else EdtTrack.Text := ''; if (ID3Tag.Genre <= High(Genres)) then CbGenre.ItemIndex := ID3Tag.Genre + 1 else CbGenre.ItemIndex := 0; end;
procedure TForm8.Button1Click(Sender: TObject); var id3Tag: Tid3Tag; begin if Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex] = '' then Exit; FillChar(id3Tag, SizeOf(TID3Tag), #0); with id3Tag do begin ID := 'TAG'; Move(EdtTitle.Text[1], Titel, Length(EdtTitle.Text)); Move(EdtArtist.Text[1], Artist, Length(EdtArtist.Text)); Move(EdtAlbum.Text[1], Album, Length(EdtAlbum.Text)); Move(EdtYear.Text[1], Year, Length(EdtYear.Text)); Move(EdtComment.Text[1], Comment, Length(EdtComment.Text)); if Length(EdtTrack.Text) > 0 then Track := StrToInt(EdtTrack.Text) else Track := 0; Genre := CbGenre.ItemIndex - 1; end; writeID3Tag(Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex], id3Tag); end;
procedure TForm8.Button2Click(Sender: TObject); begin if Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex] = '' then Exit; removeID3Tag(Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex]);
end;
end. |
wenn ich das formular dann offen habe und auf "lesen" klicke, kommt eine fehlermeldung: "Listenindex überschreitet das Maximum (-1)"
ich weiß nicht, was ich falsch gemacht habe!
Vielen Dank für eure Hilfe.
MfG
Hoellenwesen
|
|
DSS
      
Beiträge: 20
Win 98SE, Win XP
D6 Prof, D7 Prof
|
Verfasst: Mo 09.02.04 14:46
Titel: hm
die fehlermeldung (listenindex -1) bedeutet dass es nicht gefunden wurde.
ich würde es mit anderen proceduren versuchen z.B mit dieser
(die hab ich schon benutzt) man kann auch dies funktionen die man nicht brauch rausnehmen wie z.b jahr,comment
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133:
| Type TID3Tag = record ID: string[3]; Titel: string[30]; Artist: string[30]; Album: string[30]; Year: string[4]; Comment: string[30]; Genre: byte; dauer: longint; 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 = (((0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0), (0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,0), (0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,0)), ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0), (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0), (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0)), ((0,32,48, 56, 64, 80, 96,112,128,144,160,176,192,224,256,0), (0, 8,16,24, 32, 40, 48, 56, 64, 80, 96, 112,128,144,160,0), (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 ID3Tag: TID3Tag;
procedure Lese_ID3Tag(Filename: string); var Buffer: array[1..128] of char; F: File; mp3hdrread: array[1..4] of byte; mp3hdr: longint absolute mp3hdrread; tempbyte, bitrateindex, versionindex: byte; bitrate, version, layer, groese: longint; begin AssignFile(F, Filename);
Reset(F,1); groese:=filesize(f); blockread(f,mp3hdrread,4); tempbyte:=mp3hdrread[1]; mp3hdrread[1]:=mp3hdrread[4]; mp3hdrread[4]:=tempbyte; tempbyte:=mp3hdrread[2]; mp3hdrread[2]:=mp3hdrread[3]; mp3hdrread[3]:=tempbyte;
reset(f,1); Seek(F,FileSize(F)-128); BlockRead(F, Buffer, SizeOf(Buffer)); CloseFile(F); bitrateindex:=((mp3hdr shr 12) and $F); versionindex:=((mp3hdr shr 19) and $3);
case versionindex of 0: version:=3; 1: version:=0; 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; end;
procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin Lese_ID3Tag(OpenDialog1.FileName);
Titel.Caption:=ID3Tag.Titel; Artist.Caption:=ID3Tag.Artist; Album.Caption:=ID3Tag.Album; Year.Caption:=ID3Tag.Year; Comment.Caption:=ID3Tag.Comment; Genre.Caption:=IntToStr(ID3Tag.Genre);
Duration.Caption:=IntToStr(id3tag.dauer); Samplerate.Caption:=IntToStr(id3tag.sample); Bitrate.Caption:=IntToStr(id3tag.bits); Layer.caption:=IntToStr(id3tag.layers); Yersion.caption:=IntToStr(id3tag.vers); end; end; |
hoffe dir hilft das
_________________ Ik haat trance!!!
|
|
Hoellenwesen 
      
Beiträge: 17
|
Verfasst: Mo 09.02.04 21:24
Hallo
vielen dank für deine antwort, ich werde es gleich mal ausprobieren!!
aber der code sieht gut aus.
wenn es nicht klappen sollte, denn wende ich mich nochmal an dich
MfG
Hoellenwesen
|
|
|