This iPhone SDK tutorial will introduce you to the Media Player framework and the MPMoviePlayerController class. You will learn how to play videos in your iPhone applications, subscribe to notifications with NSNotificationCenter, and log messages to the console. Along the way, you will hunt down and plug a memory leak and watch the Apollo 11 crew land on the moon.
Certain aspects of applications or techniques used in this tutorial have changed since it was originally published. This might make it a little difficult to follow along. We'd recommend looking at these more recent tutorials on the same topic:
This tutorial is good for iPhone SDK beginners, as each step assumes no prior-knowledge of the Xcode environment. Intermediate developers may wish to jump straight to step 4, and those who just want to see the code snippets for playing a video can jump to steps 6 and 7.
MediaPlayer Tutorial Overview:
Step 1. Create a New View-Based Project
This step will demonstrate the creation of a new view-based application template.
Step 2. Convert the Video File to an iOS Compatible Format
This step discusses the video file formats and codecs supported by the iPhone OS, and the steps necessary to convert a video from an unsupported format to a supported format using iTunes.
Step 3. Add Project Resources
This step displays the various project files that will be used in the MoonWalk application and demonstrates the process of adding them into the project resources folder.
Step 4. Add the MediaPlayer Framework & Configure MoonWalkViewController.h
This step will demonstrate adding the MediaPlayer framework to the project and will customize the Moon Walk header file with the method prototype used in the application.
Step 5. Create the Interface with Interface Builder
This step will utilize Interface Builder to customize the application interface with the graphic files provided.
Step 6. Add the “play” Method Implementation to MoonWalkViewController
This step demos the use of the MPMoviePlayerController class in order to play the moon walk landing video.
Step 7. Add an NSNotification Callback for MPMoviePlayerPlaybackDidFinishNotification
This step introduces the user to the NSNotificationCenter and resolves the memory leak created in step 6. The NSLog() method created in step 6 is demonstrated and a small bug introduced in that function is fixed.