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.

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

WP Greet Box icon
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic, and free programming tips and tricks and source code            snippets.

3 Responses to “How to play Video in iPad”

  1. Mark says:

    This is awesome. Is there a way to add a picker view so that depending on what item you pick on the picker view, it will play a different video. Like a video juke box. Is that a lot more complicated. I’m trying to figure it out on my end, and I can’t get it.

  2. Dhanunjaya says:

    Hi Everyone,

    I am new iPhone Development. I want to develop the app called there are list of videos in a table and whenever we click on the row it will play the video from url and also it will play in certain frame in iPad.

    Can u please anyone know how to play the movie from url in certain frame in iPad.
    Plaese help me
    Thanks in advance

  3. Giannis says:

    Great Tutorial!!!!!

    I have added the code to my project but when the video ends does not take me to the main view of the app.

    I use the video as an entrance to the app.

    On iPhone device i don’t have this problem.
    Please help.

    Thanks in advance

Leave a Reply

Security Code:

learn iphone programming

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Our Mobile Training Courses

EDUmobile.ORG offers the following 4 Mobile Training Courses. Our iPhone Training Course is very popular, with over 200 developers in training.

learn iphone programming
© 2010 EDUmobile.ORG