views:

72

answers:

5

I need a button to do different things depending on how far along the person is in watching a video.

So for instance at 0-20 seconds it does thing A then at 20-25 it does thing B and 25-32 thing C

Can I make a timer that counts up and fires different messages off at specific intervals to enable/disable my buttons or change what they do?

Or should I have it fire and simultaneously start another timer and change what my button does and form a chain of events?

Thanks!

+2  A: 

do an if statement so if timer >0 and <20 seconds make button event a, if timer is >20 and <25 make button event b and so on. This way when a user clicks on the button depending on what time the timer is on then it would have changed appropriately anyway.

What you can do however which i think would be even convenient is to allow the user to press the button at anytime anyway but before any code is executed check the current position of the timer, and if the timer is > 0 but < 20 then execute EVENT a, and if timer > 20 but < 25 then execture event B this way you dont have to change the buttons but simply redirect the code that gets executed just by checking the current position of the timer. And this way there is only one timer involved.

Hope that made sense.

Its much more simpler like this rather than having the timer simultaneously fire another time, creating more timers means more objects needed to be created meaning more things to manage.

However if you want to fire multiple events and you prefer to do it that way then you do this:

http://howtomakeiphoneapps.com/2010/03/how-to-make-an-egg-timer-for-your-iphone/

Sorry i wrote this in psuedo style but im sure you have enough to understand what i am saying.

PK

Pavan
+1  A: 

NSTimer has a method setFireDate:(NSDate *)date, so instead of creating a chain of timers, you can have one timer and reschedule the next fire time as needed. Just make sure that your timer interval is large enough so that the timer won't fire before you get a chance to reschedule it.

James Huddleston
+1  A: 

Default action is A Set up a timer for B and one for C. When B-timer fired set current action to B. When C-Timer fires set current action to C.

chaos0815
is this efficient?
Pavan
in which way could this be inefficient?
chaos0815
+1  A: 

For Stage Time I set up one repeating timer as the countdown timer. On each fire, I would check the time remaining and update various UI bits appropriately.

For your app, I would go with the repeating timer approach only if I had plans for other time-based features in future releases or if I wanted to dynamically change the times for event A, B and C. Otherwise, I'd probably set up three timers at the beginning, one each for events A, B and C. That way the logic managing the time partitioning is all in one place, likely the AppDelegate, and the button change logic can all live in the View Controller.

John Franklin
A: 

What I am doing right now is starting the timer with interval of 1 and repeat: YES When it fires it calls a method which simply increments seconds(int) Within this method, which is called every 1 second, I will use a switch statement to check the value of seconds and if it is a certain value it will pause my player and invalidate the timer. This should pause the video and stop my seconds from being incremented.

I will then have a button for the user to resume the video which will play the vid and begin the same timer again and resume incrementing seconds.

My only worry is that the second count may not be accurate to the video because of processing delays at runtime dealing with the video and the switch statement being checked. I'll report back how it works.

Hippocrates