Using DelphiXE, I'm trying to show the length of a wav file on a label. This is a wav file at fixed bit rate of 64kbps that is loaded into a tMediaPlayer.
A previous SO post on the task is HERE. But no code is shown and the link to Devhood no longer appears to work so I was unable to try that method.
I also tried the code from HERE but it gives incorrect results as follows.
type
HMSRec = record
Hours: byte;
Minutes: byte;
Seconds: byte;
NotUsed: byte;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
TheLength: LongInt;
begin
{ Set time format - note that some devices don’t support tfHMS }
MediaPlayer1.TimeFormat := tfHMS;
{ Store length of currently loaded media }
TheLength := MediaPlayer1.Length;
with HMSRec(TheLength) do { Typecast TheLength as a HMSRec record }
begin
Label1.Caption := IntToStr(Hours); { Display Hours in Label1 }
Label2.Caption := IntToStr(Minutes); { Display Minutes in Label2 }
Label3.Caption := IntToStr(Seconds); { Display Seconds in Label3 }
end;
end;
This code gives a value of 24:23:4, when it should be 0:04:28.
Is there an obvious problem with that code, or is there some more elegant way to accomplish this?
As always, thanks for your help.