Autor Beitrag
Roy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 21.04.07 16:08 
Hallo Profis und Laien,

habe im folgenden Quelltext Probleme beim anzeigen der Titellänge! Er rundet den Wert auf möchte aber bis auf zwei Stellen nach dem Komma anzeigen lassen.

So schaut mal ob ihr was sehen könnt?

die procedure Lese_ID3Tag(Filename: string);

ausblenden volle Höhe Delphi-Quelltext
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:
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; //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) div ((bitrate)*1000)div 59;
    bits:=bitrate;
    vers:=version;
    layers:=layer;
    end;
  end;


und das aufrufen
procedure TForm1.Image5Click(Sender: TObject);

ausblenden Delphi-Quelltext
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:
procedure TForm1.Image5Click(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:=FloatToStr(id3tag.dauer);
    Samplerate.Caption:=IntToStr(id3tag.sample)+' kHz';
    Bitrate.Caption:=IntToStr(id3tag.bits)+' kbps';
    Layer.caption:=IntToStr(id3tag.layers);
    Yersion.caption:=IntToStr(id3tag.vers);
    Duration1.Text:=FloatToStr(id3tag.dauer);

  end;
    with MediaPlayer1 do begin
    FileName := OpenDialog1.FileName;
    Image2.Visible:=false;
    Image3.Visible:=true;
    Animate1.Active:=true;
    Open;
    Play;
end;
end;


also es funktioniert aber er rundet!

Kann mir wer helfen?
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 21.04.07 16:11 
Dauer aus ID3Tag als Extended (ID3Tag ist vermutlich ein Record) deklarieren, dann diese Zeile:
ausblenden Delphi-Quelltext
1:
dauer:=(groese) div ((bitrate)*1000)div 59;					

durch diese ersetzen:
ausblenden Delphi-Quelltext
1:
Dauer := RoundTo((Groese) / ((Bitrate) * 1000) / 59), -2);					

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Roy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 21.04.07 16:48 
So habe es eben versucht und komme irgendwie nicht klar. Kannst du den oberen Quelltext mit deinem Vorschlag mal ändern wie du dir das vorgestellt hast?

Bitte
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 21.04.07 16:51 
Kann ich so nicht, weil ich nicht weiß, wie ID3Tag deklariert ist. Wenn du aber den kompletten Source postest, kann ich das durchaus.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 21.04.07 16:51 
Nur so am Rande: Die Bestimmung von "dauer" dürfte in ca. 80% aller Fälle schief gehen. Gründe:

  • eine mp3-Datei muss nicht mit einem mpeg-Header anfangen. Manchmal steht da Müll, sehr oft aber ein ID3v2-Tag. Folge: Die Bestimmung der Bitrate geht schief. Abhilfe: In der Datei einen gültigen MPEG-Header suchen.
  • viele mp3-Dateien haben eine variable Bitrate, die gerade am Anfang und Ende stark von der durchschnittlichen Bitrate abweichen kann. Wenn also Punkt 1 nicht eingetreten ist, dann werden hierdurch falsche Ergebnisse geliefert. Tatsächlich hat bei vbr-Dateien der erste MPEG-Frame eine Bitrate von 32 kBits, weil sich in diesem Frame ein Xing-Header versteckt, in dem weitere nützliche Informationen stecken. Abhilfe: Alle MPEG-Frames zählen und aus der Anzahl dieser die Dauier berechnen oder den Xing-Header erkennen uns auswerten.
  • Die Formel für die Dauer kommt mir generell komsich vor - besonders die 59. Wo hast du die denn her?


Abhilfe generell: MP3FileUtils benutzen, oder die Unit in diesem Beitrag.

_________________
We are, we were and will not be.
Roy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 21.04.07 17:13 
ja stimmt, die 59 ist noch aus einer Probe. Hatte erst den Divisor 60 weil er mir als Wert bis jetzt sekunden gibt. Dachte mit dem Wert 59 einen ungerundeten mit Nachkommastellen enthaltenen Wert zu bekommen.

Habe es probiert und mit dem div kommt es auch ungefähr hin, aber wie gesagt nur in Etwa.
Roy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 21.04.07 17:15 
So hier ist der Komplette Quelltext:

ausblenden volle Höhe Delphi-Quelltext
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:
239:
240:
241:
242:
243:
244:
245:
246:
247:
unit temple;

interface

uses
  Windows, Messages,SysUtils,mmsystem, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, jpeg, ExtCtrls, MPlayer, StdCtrls, WebAdapt, WebComp, ComCtrls, Mask,
  DBCtrls;

type
  TForm1 = class(TForm)
    Image1: TImage;
    MediaPlayer1: TMediaPlayer;
    Image4: TImage;
    Panel1: TPanel;
    Image3: TImage;
    OpenDialog1: TOpenDialog;
    Image5: TImage;
    Panel2: TPanel;
    Samplerate: TLabel;
    Duration: TLabel;
    Yersion: TLabel;
    Layer: TLabel;
    Bitrate: TLabel;
    Image2: TImage;
    Image8: TImage;
    Image7: TImage;
    Album: TLabel;
    Artist: TLabel;
    Titel: TLabel;
    Year: TLabel;
    Comment: TLabel;
    Genre: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Image6: TImage;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Panel3: TPanel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    Label17: TLabel;
    Animate1: TAnimate;
    Timer1: TTimer;
    procedure Image7Click(Sender: TObject);
    procedure Image8Click(Sender: TObject);
    procedure Image6Click(Sender: TObject);
    procedure Image2Click(Sender: TObject);
    procedure Image5Click(Sender: TObject);
    procedure Image3Click(Sender: TObject);
  private
  procedure WMNCHitTest(var M: TWMNCHitTest);
  message wm_NCHitTest;
  public
    { Public-Deklarationen }
  end;
 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; //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;
  aStringlist: TStringlist;
lied: integer = 0;
implementation

{$R *.dfm}


procedure TForm1.Image3Click(Sender: TObject);
begin
MediaPlayer1.Stop;
Image3.Visible:=false;
Animate1.Active:=false;
Image2.Visible:=true
end;

 procedure TForm1.WMNCHitTest (var M: TWMNCHitTest);
begin
  inherited;
  if M.Result = htClient then 
    M.Result := htCaption;
end;

 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; //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) div ((bitrate)*1000)div 59;
    bits:=bitrate;
    vers:=version;
    layers:=layer;
    end;
  end;

procedure TForm1.Image5Click(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:=FloatToStr(id3tag.dauer);
    Samplerate.Caption:=IntToStr(id3tag.sample)+' kHz';
    Bitrate.Caption:=IntToStr(id3tag.bits)+' kbps';
    Layer.caption:=IntToStr(id3tag.layers);
    Yersion.caption:=IntToStr(id3tag.vers);
     end;
    with MediaPlayer1 do begin
    FileName := OpenDialog1.FileName;
    Image2.Visible:=false;
    Image3.Visible:=true;
    Animate1.Active:=true;
    Open;
    Play;
end;
end;
procedure TForm1.Image2Click(Sender: TObject);
begin
MediaPlayer1.Play;
Image3.Visible:=true;
Animate1.Active:=true;
Image2.Visible:=false
end;

procedure TForm1.Image6Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Image8Click(Sender: TObject);
begin
MediaPlayer1.Next
end;

procedure TForm1.Image7Click(Sender: TObject);
begin
MediaPlayer1.Previous
end;

end.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 21.04.07 17:17 
ausblenden Delphi-Quelltext
 
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
{ ... }
  TID3Tag = record  
    ID: string[3];  
    Titel: string[30];  
    Artist: string[30];  
    Album: string[30];  
    Year: string[4];  
    Comment: string[30];  
    Genre: byte;  
    Dauer: Extended; //in sekunden;  
    sample: integer;  
    bits: byte;  
    vers: byte;  
    layers: byte;  
end;  

// ...


Und die Zeile aus meinem vorherigen Beitrag.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Roy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: Sa 21.04.07 19:59 
Er meldet mir jetzt hier Fehler:


ausblenden Delphi-Quelltext
1:
dauer:=RoundTo((Groese) / ((Bitrate) * 1000) / 59), -2);					
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 21.04.07 21:13 
Unit Math einbinden.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Roy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: So 22.04.07 09:35 
Vielen Dank es hat funktioniert.

ausblenden Delphi-Quelltext
1:
dauer:=RoundTo((Groese) / ((Bitrate) * 1000) / 60,-2);					


Darf ich ihnen noch weitere Fragen bezüglich eines Players stellen?

Gruß Roy
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 22.04.07 09:48 
Latürnich :mrgreen:

Aber wenns nix mit der Dauer zu tun hat: Neuen Thread aufmachen ;-)

_________________
We are, we were and will not be.
Roy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 184

Windows7 Ultimate
Delphi 2007, NET, Embarcadero
BeitragVerfasst: So 22.04.07 10:16 
ja na klar. Thema ist hiermit Abgeschlossen, danke nochmal an alle.