MPMoviePlayerController

To present video in your application use MPMoviePlayerController Class. Place it in UIViewController Class that is initialized with an url.

– (id) initWithURL:(NSURL*)theURL
{
self = [super init];
if (self != nil)
{
[self setUrl:theURL];
}
return self;
}

Initialize player with url. Change player’s control style or remove controls. Select type of scaling (fit, fil, none).

MPMoviePlayerController *theMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:self.url];
theMoviePlayer.controlStyle = MPMovieControlStyleDefault;
theMoviePlayer.shouldAutoplay = YES;
theMoviePlayer.view.backgroundColor = [UIColor clearColor];
[theMoviePlayer.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin];
[theMoviePlayer setScalingMode:MPMovieScalingModeAspectFit];
[self setMoviePlayer:theMoviePlayer];
[theMoviePlayer release];

While video is loading spinner is shown. It will disappear when player sends notification: MPMediaPlaybackIsPreparedToPlayDidChangeNotification.

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self selector: @selector(hideSpinner) name: MPMediaPlaybackIsPreparedToPlayDidChangeNotification object: self.moviePlayer];
In the navigation bar there is a “Refresh Button” which reloads player’s contentURL.

[self.moviePlayer stop];
[self.moviePlayer setContentURL:self.url];
[self.moviePlayer play];

This control is easily implemented in any iPhone / iPad application.