Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

.length to minutes and seconds format

Posted on 1998-05-04
17
Medium Priority
?
216 Views
Last Modified: 2010-04-06
hi,

I making a program using the mpegdll.dll, it has a .length property, to display the time, but it is in milliseconds. I tried converting it to Minutes and seconds but had no luck, can anyone show me how to do it. Currently I have this

T := ((MPEG1.Length div 1000) div 60);
I := IntToStr(T);
Label3.Caption := I

Now the time I get is rounded like say 4 minutes, how do I get the seconds too, and how to format the label so it is displayed like this 0:00 (Minutes:Seconds). I'm not even sure my calculation is correct so please show the full procedure.
Thanks
0
Comment
Question by:hellfire052497
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 2
  • +1
17 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 400 total points
ID: 1341169
Hi Hellfire,

If you use div you will always get an integer; It rounds everything so you can assign the result to an integer.

Use / and you get a float or double ---> if you need numbers after comma, just take this float minus the integer part of it and you got it!

Regards ZiF.
0
 

Author Comment

by:hellfire052497
ID: 1341170
Ok, but how do I format the Label. Can you show me
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341171
Well, I assume we can't use TimeToStr --> this uses the numbers behind the comma as time...

We could do it like this :

T := ((MPEG1.Length / 1000) / 60);

label3.Caption := IntToStr(Trunc(T)) + ':'+IntToStr(Frac(T));

Regards, Zif.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:hellfire052497
ID: 1341172
I got the double, but I cannot convert it to Integer, I always get "invalid typecast) when using S := (Integer(T));
A sample would help.
Thanks
0
 

Author Comment

by:hellfire052497
ID: 1341173
Added the last question before your second answer, will try that first.
0
 

Author Comment

by:hellfire052497
ID: 1341174
nope, double and string are no go. Still no luck with the Double to Integer part.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341175
Hi hellfire,

T is double? Correct?
S is String? Correct?

To translate T to string you must use FloatToStr....

OR to get minutes ... You need :

 IntToStr(Trunc(T)) ---> Trunc gets the integer value of T;

to get minutes :
 
 Frac(T) ---> gets the fractional part of T....

So if you got 2 values after comma --->

var seconds : string;
 
 seconds :=  Trunc(Frac(T)*100);

 Label3.Caption := IntToStr(Trunc(T)) + ':'+IntToStr(Trunc(Frac(T)*100));
0
 

Author Comment

by:hellfire052497
ID: 1341176
I must be missing something here,

ok here is the full code

Var
T : Double;
Begin
T := ((MPEG1.length /1000) /60);
Label3.Caption := IntToStr(Trunc(T))+':'+ IntToStr(Frac(T)*100); =>> here I get Incompatible types Integer and Real.
Any ideas
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341177
Yep ... Sorry... I corrected this in my last comment .... Forgot to tell you about this...

See Frac returns a real value.... So, we do this :

 If frac(T) is 0.32 ---> * 100 --> 32 ---> change to integer ---> Trunc(32)

This is the code --> IntToStr(Trunc(Frac(T)*100));

Regards, Zif.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1341178
Hi guys,
maybe this is all you need. Drop a TButton, a TLabel and a TEdit on a blank form and put this in the buttons OnClick handler. Now you can test the format of milliseconds to HH:MM:SS:FF.

procedure TForm1.Button1Click(Sender: TObject);
// frames in 25 fps (PAL), can also be 30 (NTSC)
const FPS = 30;
var H, M, S, F, MS : Integer;
begin
  MS := StrToInt(Edit1.Text);
  H := (((MS div 1000) div 60) div 60) mod 60;
  M := ((MS div 1000) div 60) mod 60;
  S := (MS div 1000) mod 60;
  F := ((MS mod 1000) * FPS) div 1000;
  Label1.Caption := Format('%.2d:%.2d:%.2d-%.2d', [H, M, S, F]);
end;

This function outputs *very* fast.

Slash/d003303
0
 

Author Comment

by:hellfire052497
ID: 1341179
it all works now, thanks for the answer
0
 
LVL 6

Expert Comment

by:Holger101497
ID: 1341180
he he... quite some time later (I got here through hellfire's profile and couldn't resist checking if the answer was the one I'd give...)

When reading this thread, I just wanted to say that IntToStr is rather slow and using and rounding lots of floats doesn't help either...

I guess the fastest/shortest way of doing this is:
Label1.Caption:=Format('%d:%.2d', [MPEG1.Length DIV 60000, MPEG1.Length DIV 1000 MOD 60]);
This doesn't display hours, but I think that's ok... few Mpegs will last more than one hour and even then, something like "87 minutes" is quite normal for movies...

P.S.: d003303, what does H := (((MS div 1000) div 60) div 60) mod 60; do? Are you a workaholic and your day "only" has 60 hours? *bg*
0
 

Author Comment

by:hellfire052497
ID: 1341181
Thanks i'll try it out.
0
 
LVL 4

Expert Comment

by:d003303
ID: 1341182
Holger,
hehe, workaholic might be... maybe E-E-holic ;-)
0
 
LVL 6

Expert Comment

by:Holger101497
ID: 1341183
Oh, btw (just to keep this thread alive *lol*):
ZifNab's a workaholic as well... his minute has 100 seconds!
hellfire: If you used ZifNab's code, you should change IntToStr(Trunc(Frac(T)*100)); to IntToStr(Trunc(Frac(T)*60));... but that code is kinda weird/slow anyway!
0
 

Author Comment

by:hellfire052497
ID: 1341184
I noticed then, and I did changed it to 60.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1341185
my, my am I under fire in this thread. Sorry for my mistakes people... As I said earlier, I'm not god and I just try to help as much as I can. See my state too, i'm not a programmer like some good people around here.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question