resolve timer logic [closed]
i did fastforward in music player by getting current time of the player (30 sec forward)
if(sec>=maxsec && min>=maxmin && hour>=maxhour)
{
next_buttonclick(null);
}
else
{
sec=sec+30;
if(sec>=60)
{
sec=sec%60;
min=min+1;
if(min>=60)
{
min=min%60;
开发者_开发知识库 hour=hour+1;
}
}
max is the time duration of media..
when i run this, it not working properly.. plz fix bug free..
also reverse
if(sec<=0 && min<=0 && hour<=0)
{
back_buttonclick(null);
}
else
{
gettimeduration();
sec=sec-30;
if(sec<0)
{
sec=60+sec;
min=min-1;
if(min<0)
{
min=60+sec;
hour=hour-1;
}
}
thanks in advance..
I think the condition
(sec>=maxsec && min>=maxmin && hour>=maxhour)
doesn't do what you think it should.
Imagine that maxsec
is 30; maxmin
is 6, and maxhour
is 0. And let's say sec
is 17, min
is 8, and hour
is 0. So the maxtime is 6 and a half minutes and the current time is 8 minutes and 17 seconds.
17 >= 30 FALSE and the whole condition becomes false
The best thing to do when comparing times is to convert to seconds and compare just the seconds
(sec + min*60 + hour*3600 >= maxsec + maxmin*60 + maxhour*3600)
精彩评论