1. Include MediaPlayer framework in the project
2. Import header file in the view controller
3. Declare the player instance in the controller header file:
MPMoviePlayerViewController *playerViewController;
Sample Code :
----------------
- (void) playVideo:(NSString *)fileName{
NSString *url = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
[self.view addSubview:playerViewController.view];
//play movie
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
// The call back
- (void) movieFinishedCallback:(NSNotification*) aNotification
{
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
player.initialPlaybackTime = -1;
[player stop];
[player.view removeFromSuperview];
[player release];
}
No comments:
Post a Comment