macdevcenter.com
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

Integrating QuickTime with Cocoa
Pages: 1, 2, 3

Step Four: Completing the Project Setup

Returning to Project Builder, the project setup is completed by organizing the source code and resource files.

In addition to the template files that are provided when NSMovie_Example was created, I have already added files for the button images (Play.tiff and Pause.tiff) and the controller object (NSMovie_Example_Controller.m and NSMovie_Example_controller.h). To complete the project, I added three more files:

  • QuickTime.Framework is a Cocoa framework that contains all of the headers and libraries needed to build, link, and execute a QuickTime-enabled application.
  • Time_Display_String.m is a C routine, borrowed from an existing application, that converts a number of seconds into an NSString that represents the movie's time in minutes and seconds.
  • einsteins_legacy.mov is the movie that NSMovie_Example will play.

Once these were added, I created a couple of new groups within the project, and the result is a "Groups & Files" tab that looks like the following:

Figure 7. NSMovie_Example Project Builder Groups & Files
Figure 7. NSMovie_Example Project Builder Groups & Files

Step Five: Completing the Source Code for NSMovie_Example_Controllers

To finish the coding, I needed to add the logic for the Action methods in the NSMovie_Example_Controller. In addition to the four Action methods I had specified in the Interface Builder, I needed to add two more methods to the controller: -awakeFromNib and -Update_Player_Feedback.

Here's the pseudo-code description for each method:

  • - (void) awakeFromNib

This method completes the initialization of the controller object. The main tasks are to load the movie einsteins_legacy.mov from the application bundle, make the resulting NSMovie object the current movie in Movie_View, initialize Time_Display, and set the parameters of Scrub_Slider to match the duration of the newly loaded movie.

  • (IBAction) Scrub_Movie: (id)sender

This method is invoked when someone moves the scrub slider. The main task is to adjust the movie's current time (using SetMovieTimeValue()) to mirror the value represented by the slider's current position. Additionally, Time_Display must be updated to reflect the current movie time.

  • (IBAction) Set_Volume: (id)sender

This method is invoked when the user moves the volume slider. The main task is to adjust the Movie_View's volume to reflect the current position of Volume_Slider.

  • (IBAction) Start_Movie: (id)sender

This method is invoked after a user clicks the Control_Button (in its normal state). The main tasks are to start playback in the Movie_View and adjust the action of the Control_Button so that the next click will stop the movie. This method also creates a repeating NSTimer (Scrub_Timer) that fires every tenth of a second, sending a message to -Update_Player_Feedback, which in turn animates Scrub_Slider and Time_Display.

  • (IBAction) Stop_Movie: (id)sender

This method is invoked after a user clicks the Control_Button (in its alternate state). The main tasks are to stop playback in the Movie_View and adjust the action of the Control_Button so that the next click will start the movie. This method also stops the repeating time (Scrub_Timer) and resets Scrub_Slider to its initial position.

  • (void) Update_Player_Feedback: (NSTimer *) Incoming_Timer

This method is invoked every tenth of second by Scrub_Timer. The main task is to animate Scrub_Slider and Time_Display to reflect the current playback time of Movie_View. If Movie_View is done playing, then movie playback is stopped and Scrub_Slider and Time_Display are reset to their initial values.

Step Six: Compile It and Watch My Movie

Special thanks to my friend Wes Vasher. He's responsible for whipping up a short movie for this project.

We've Only Just Begun ...

Hopefully, I've given you enough to get you going on integrating QuickTime into your next Cocoa project.

This QuickTime overview is just the tip of the iceberg. Before you take on your own project, I suggest that you dig deeply into the QuickTime reference materials available at Apple's Developer site. Most notably, check out the QuickTime sample code that uses Cocoa.

The NSMovie_Example project is a place to start, but by no means does it encompass all the functionality that QuickTime makes available to you. I would suggest that you take the source code, play with it and modify it to your own purposes (try adding a movie to your About Box).

That's all for now!

Douglas Welton is the president of Einstein's Legacy that created Cinematics, an innovative new media player that helps you to build and manage playlists of digital movies on your Macintosh.


Return to MacDevCenter.com