Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a video player that I want to build.
i have a horizontal scroll bar
C#
lenghtMovieLoaded = video.Duration;   //(Retrieves the length, in seconds, of the video file.)
hScrollBar1.Maximum = (int)Math.Round(lenghtMovieLoaded); //maximum of scrollbar


Lets say, my video.Duration is 1000 sec in total.

Now,in a label i want to show the 1-[current time] of the video /and the 2-[total time].
Something like: //label2.Text = "1-[00:00]/2-[00:00]";

I need to convert 1000 sec into minutes = easy part>>
video.Duration/60 and I have the current minutes.

Now... the problem is the "seconds" part... I need to increment them from 0- 60 while the hScrollBar1 is moving, and not go over 60 but to restart from 0 -60 and so on, AND to be accurate with the track.
If I am at 1min33sec the "sec" part must not be a erroneous mathematical trick.

I do not know what to search in Google for. An algorithm I suppose...
Or, if you know a tutorial about this thing...
Im not very good at math also :) heh - im an artist so...
help?
and thank you.
Posted
Updated 11-Sep-14 8:10am
v4

The TimeSpan struct is your friend!
Just create a new TimeSpan from the count in seconds, and use its .ToString(formatString) to format it:
C#
TimeSpan elapsed = TimeSpan.FromSeconds(elapsedTimeSecondsCounter);
string elapsedFormatted = elapsed.ToString(@"m\:ss");
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 11-Sep-14 14:38pm    
Sure, a 5.
—SA
_Q12_ 12-Sep-14 12:55pm    
Thank you - your code is actually resolve the problem... I must definitively play more with this TimeSpan thing and find out at what is Best good for... :) If you have, a good tutorial that you know of and explain it best, about this TimeSpan, please put it here. Thanks.
int total_seconds = 1000;
int hours = total_seconds / 3600;
int minutes = total_seconds / 60 % 60;
int seconds = total seconds %  60;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900