Browsing articles tagged with " MPMoviePlayerController"

How to Play a Video With MPMoviePlayerController

Dec 20, 2009   //   by Derek van Vliet   //   Development  //  6 Comments

Splash screens, cutscenes, tutorials or just good old content. There are plenty of reasons to need to play a video in your iPhone app. Here’s how to do it in 3 simple steps:

1. Add the MediaPlayer framework to your target.

2. Import the MediaPlayer header file in the file you intend to begin playing the video in, like so:

#import <MediaPlayer/MediaPlayer.h>

3a. Now we can stream a video from the internet like so:

NSURL *url = [NSURL URLWithString:@""];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[player play];

3b. Alternately, we can stream a video that you include in your app bundle. To stream a file called myvideo.m4v, you would run the following code:

NSString *path = [[NSBundle mainBundle] pathForResource:@"myvideo" ofType:@"m4v"];
NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[player play];

Our Games

Latest Tweets