Graphics Reference
In-Depth Information
To update the slider's current position, a timer is implemented whenever playback has
started. To add this, update the code for the -togglePlayback action, as shown in
Listing 7-4.
LISTING 7-4
Implementing a Timer
- ( IBAction )togglePlayback:( id )sender;
{
if ( [movie rate] != 0.0 )
{
[movie stop ];
[timer invalidate ];
}
else
{
[movie play];
timer = [ NSTimer
scheduledTimerWithTimeInterval :0.02
target : self
selector : @selector (updateSlider:)
userInfo : NULL
repeats : YES ];
}
}
The instance variable timer is instantiated whenever the movie starts playing. When the
movie is stopped, we need to stop the timer by calling -invalidate on it.
The selector used on each tick of the timer is called -updateSlider . The implementa-
tion for this selector is shown in Listing 7-5.
LISTING 7-5
Implementing the Timer Selector
- ( void )updateSlider:( NSTimer *)theTimer;
{
QTTime current = [movie currentTime];
double value = ( double )current.timeValue /
( double )movieDuration.timeValue;
[slider setDoubleValue:value];
[slider setNeedsDisplay ];
}
This selector first obtains the current time and divides that by the movie's total time,
which is stored in the movieDuration instance variable. This returns a value between 0.0
 
Search WWH ::




Custom Search