How to play Video in iPad

This is the very simple application . In this application we will see how to play video in the iPad.

Step 1: Create a View base application using template. Give the application name “VideoPlay_iPad”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Xpand classes and notice Interface Builder created the VideoPlay_iPadViewController class for you. Expand Resources and notice the template generated a separate nib,VideoPlay_iPadViewController.xib, for the “VideoPlay_iPad”.

Step 4: We need to add MediaPlayer.framework in the Frameworks folder. Select-> Frameworks folder -> Add ->Existing Frameworks -> then select MediaPlayer.framework.

Step 5: In the VideoPlay_iPadViewController.h file, we have created instance of MPMoviePlayerController class, that manage the playback of a movie from a file or from the network, and create a instance of NSURL class . So make the following changes in the file.

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface VideoPlay_iPadViewController : UIViewController {

        MPMoviePlayerController *videoPlayer;
        NSURL *videoURL;
       
}

Step 6: Open the VideoPlay_iPadViewController.m file and make the following changes in the file.

(void)viewWillAppear:(BOOL)animated
{
        NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"3idiots.mov" ofType:nil];
        NSURL *url = [NSURL fileURLWithPath:urlStr];
        videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
        [self.view addSubview:videoPlayer.view];
        videoPlayer.view.frame = CGRectMake(0, 0,768, 1000);  
        [videoPlayer play];
}

Step 7: Now compile and run the application in the Simulator.

You can Download SourceCode from here VideoPlay_iPad