PLAYING VIDEO ON THE IPHONE

Playing videos is one of the most commonly performed tasks on the iPhone. Prior to iOS 4 for the iPhone, all videos had to be played full-screen. However, starting with iOS 4, this rule has been relaxed; you can now embed videos within your iPhone applications. This makes it possible for you to embed more than one video in any View window. This section shows you how to enable video playback in your iPhone applications.

TRY IT OUT: Enabling Video Playback

image

  1. Using Xcode, create a new Single View Application (iPhone) project and name it PlayVideo. You will also use the project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Drag a sample video into the Supporting Files folder of your Xcode project (see Figure 13-11).

    image

    FIGURE 13-11

  3. Double-click on the project name in Xcode and select the PlayVideo target. Select the Build Phases tab on the right and expand the section Link Binary With Libraries (3 items). Click the “+” button (see Figure 13-12).

    image

    FIGURE 13-12

  4. Select MediaPlayer.framework to add it to your project (see Figure 13-13).

    FIGURE 13-13

  5. In the PlayVideoViewController.h file, code the following ...

Get Beginning iOS 5 Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.