Graphics Reference
In-Depth Information
front, add the movie layer to the root layer, giving it an index of zero with a call to
-insertSublayer:atIndex . Finally, change the -awakeFromNib call to -addSublayer to use
the -insertSublayer:atIndex call instead, as follows:
[[[window contentView ] layer ] insertSublayer :layer atIndex :0];
Now if you run the project, the buttons are overlaid on top of the video, enabling you to
click them and control the movie.
Tracking Progress and Changing Frames with a Slider
To complete our basic player functionality, we add a slider to the interface that provides a
playback progress bar and displays the playback time across the top of the video. First,
create an action in Xcode to handle changes to the slider, as shown in Listing 7-3.
LISTING 7-3
Implementing Slider Action
- ( IBAction )sliderMoved:( id )sender;
{
long long timeValue = movieDuration.timeValue * [slider doubleValue ];
[movie setCurrentTime:QTMakeTime(timeValue,
movieDuration.timeScale)];
}
The slider will have a minimum of 0.0 and a maximum of 1.0 . Set these values in
Interface Builder by selecting the slider with a single mouse click and then providing the
values in the slider minimum and maximum fields in the Slider Attributes Inspector. The
slider value then provides a decimal fraction that when multiplied by total duration of
the movie yields the current time in the movie. Use this time to set the currentTime of
the QTMovie object when the slider position is changed. To do so, construct a QTTime
structure by calling QTMakeTime with the time value you calculated and pass that to the
movie's -setCurrentTime . This causes the QTMovieLayer to update the view to the current
frame.
To obtain the current slider value (between 0.0 and 1.0 as we specified in Interface
Builder) in code, you also need to create an NSSlider outlet in the AppDelegate by adding
the following line to the header file:
IBOutlet NSSlider *slider;
In Interface Builder, add an NSSlider control to the window and make the connections
from the AppDelegate to the slider control and from the slider control back to the
AppDelegate 's -sliderMoved action. Figures 7-2 and 7-3 demonstrate how to drag these
connections in Interface Builder .
 
Search WWH ::




Custom Search