0

I'm developing a video player and am trying to get the seconds and minutes to reset at 60 seconds/minutes.

At the moment I can get it to run perfectly but I cant reset the Integer/String to 00 when it hits 60.

How do i do this?

My current code:

pos = vv.getCurrentPosition();
sec = pos / 1000;
min = pos / 60000;
hr = pos / 3600000;

if (sec == 60) {
    sec = vv.getCurrentPosition();
}
if (min == 60) {
    min = vv.getCurrentPosition();
}

secs = Integer.toString(sec);
mins = Integer.toString(min) + ":";
hrs = Integer.toString(hr) + ":";

if (sec < 10) {
    secs = "0" + sec;
}
if (min < 10) {
    mins = "0" + min + ":";
}
if (hr < 10) {
    hrs = "0" + hr + ":";
}

if (hr == 00) {
    hrs = "";
}

hms = hrs + mins + secs;

tvProgress.setText(hms);

Thanks in advance

Timmo
  • 2,266
  • 4
  • 34
  • 54
  • http://stackoverflow.com/questions/17480936/how-to-display-the-timer-in-android/17481173#17481173. check this might help. – Raghunandan Jul 06 '13 at 14:52
  • This isn't what i want sorry. I want to change the integer when it hits 60 to reset to 0. So its obviously if(sec==0){.... but its what to put inside the statement i need to know – Timmo Jul 06 '13 at 14:58
  • you can reset your textview when it reaches 0. in the example posted it will set text to done when it reaches 0. I guess you are looking for a countdown timer. if so check the link posted might help. – Raghunandan Jul 06 '13 at 15:01
  • Yes but this is what id want maybe in a clock but this in this case i am playing a video so a countdowntimer wont work.... – Timmo Jul 06 '13 at 15:06
  • you can set the countdown timer to count down based on the video play time. Suppose your video pls for 30 minutes set your count down timer to count down from 30 minutes. when reaches 0 you can re set the text. – Raghunandan Jul 06 '13 at 15:08
  • No this wont work. After 60 seconds of playback on the video i need to subtract 60 then start again but this always ends up sticking at 0 or carrying on counting up. – Timmo Jul 06 '13 at 15:20
  • i am sorry i din't understand your comment. may be you can wait for an alternative answer. – Raghunandan Jul 06 '13 at 15:22

2 Answers2

1

What is just wrong with setting it by doing something like this? int displaySeconds = secs % 60 That way you don't modify seconds for any other sort of logic you need, plus this will always give you a number from 0 - 59.

Also, look into String.format to set your strings instead of doing it that way you have it now.

Jonathan
  • 3,369
  • 4
  • 22
  • 27
0

Tryed sth like that:

final Runnable r = new Runnable()
{
    public void run() 
    {
        tv.append("Hello World");
        handler.postDelayed(this, 1000);
    }
};

handler.postDelayed(r, 1000);
Matthias H
  • 1,300
  • 13
  • 19
  • Im already usig the handler runnable methods to update it. i need to know how to reset the integer to 0 when it hits 60 – Timmo Jul 06 '13 at 15:00