Chapter 14. Media Player Framework
The Media Player framework makes it ridiculously easy to add video and audio playing capabilities to your application. The movie player controller automatically handles the orientation changes and window transitions to play many different video formats on the iPhone’s screen. A single call to the movie controller to play the movie will automatically display the player and its controls. The application can choose which controls to display, adjust the playback position, and control the video’s play and stop functions. The movie player supports MOV, MP4, M4V, and 3GP formats, as well as many audio formats.
To use the Media Player framework, you’ll need to add it to your Xcode project. Right-click on the Frameworks folder in your project, and then choose Add Framework. Navigate to the MediaPlayer.framework folder, and then click Add.
Movie Player Controllers
The MPMoviePlayerController
class is initialized with an NSURL
object, which you’ve already learned
about. You can instantiate the NSURL
class to refer to a local file or a remote website URL. To initialize
the movie player controller, use the class’s initWithContentURL
method and provide an
NSURL
object. An example
follows:
MPMoviePlayerController *moviePlayer = [ [ MPMoviePlayerController alloc ] initWithContentURL: [ NSURL URLWithString: @"http:// ..." ] ];
To initialize a movie player to play a local file, use the
NSURL
class’s fileURLWithPath
method:
NSString *path = [ NSString stringWithFormat: ...
Get iPhone SDK 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.