iPhone Game Development - Chris Craft [46]
Also note that the MPMoviePlayerController class can play local movies stored on the iPhone or remote movies from a network-based URL. If you decide to use remote movies, consider saving your movie files in the iPhone Cellular format of 3gp. Again, you can use QuickTime Pro to accomplish this feat. The 3gp format is optimized for the iPhone and for retrieval over cellular connections.
Tip
If your application is larger than 10MB, users will not be able to download it from the App Store using cellular connections. Instead, a Wi-Fi connection will be required. Consider streaming larger videos from remote servers to keep app file size down.
The MPMoviePlayerController class allows you to play any movie or audio format that is already supported on the iPhone. This means if it already works on the device, it will work in your application—or more specifically, files with the following extensions will work in your application: MOV, MP4, MPV, and 3gp.
Any time you are working with a new class, it's a good idea to research it first in Xcode's Help menu. Go ahead and take a few minutes to look up MPMoviePlayerController in Xcode's API Reference. One easy way to do this is to type MPMoviePlayerController in Xcode and then right-click the text and choose Find Selected Text in API Reference.
Also consider using the Reference Assistant located under Xcode's Help menu. This gives you real-time, context-sensitive help as you work in Xcode. Finally, you can right-click MPMoviePlayerController and choose Jump to Definition. This takes you directly to the real code that makes up the MPMoviePlayerController class. Not only can you learn more about the MPMoviePlayerController class, but this is a great way to learn more about how to program correctly.
You will need to add the MediaPlayer framework to your iFlame Xcode project. To do this, find the Frameworks folder, which is located under the iFlame project in the Groups & Files panel of Xcode, and double-click on the folder to expand it (Figure 4.5).
Right-click on the Frameworks folder and choose the Existing Frameworks option from the Add sub-menu. You will now see a folder listing; find the folder named Frameworks and double-click it to expand it. You will see a listing of a dozen or more framework folders. Once you locate the MediaPlayer.framework folder, select it and then click the Add button in the bottom right.
Note that depending upon a number of factors, such as the current SDK version installed and whether the Developer Tools were already installed, you may not be placed in the correct Framework folder by default when trying to add an existing framework. If this happens to you, you will need to browse up a parent folder or two and find the correct version of the framework. The full location for the MediaPlayer.framework is Developer⇒Platforms⇒iPhoneOS.platform⇒Developer⇒SDKs⇒iPhoneOS3.0.sdk⇒System⇒Library⇒Frameworks⇒MediaPlayer.framework.
FIGURE 4.5
The Frameworks folder
Another screen appears, similar to Figure 4.6. Confirm that Reference Type is set to Default and Text Encoding is set to Unicode (UTF-8). The Add To Targets panel should have iFlame listed with a check box next to it. Click the Add button to proceed. These are the default settings, so you should only have to double-click to confirm them.
You now have added a reference to the MediaPlayer.framework to your iFlame project. The next step is to update your iFlameAppDelegate.h file so that it will use this framework. You can find the iFlameAppDelegate.h file in Xcode under the Classes folder beneath the iFlame root project folder. You can do this by adding a simple import statement to the top of the file:
#import FIGURE 4.6 Adding a new framework to the iFlame app
Once you have added this line, your iFlameAppDelegate.h file should look like the following: