<

Embedding
Video

>

 

Create a Single View Application

Add MediaPlayer.Framework
File > Add Files to

Create a new View Controller. Add a button that will start the movie.

BWViewController.h

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

 

Make a connection between your button and the ViewController.h file

Control click from the button to the ViewController.h file and drag to the line after @interface NMViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>

Make the Connection an "A ction" name the button and make it type "id" and keep it "Touch up inside"

// NMViewController.m

#import "NMViewController.h"

@interface NMViewController ()
{
MPMoviePlayerController *mpc;
}

@end

 

// NMViewController.m

- (IBAction)PlayButton:(id)sender {

NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"nameofvideo" ofType:@"mp4"];
// of type can be mp4, mov, etc

NSURL *url = [NSURL fileURLWithPath:stringPath];

mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];
[mpc setMovieSourceType:MPMovieSourceTypeFile];

[[self view]addSubview:mpc.view];
//[mpc setFullscreen:YES];
[[mpc view] setFrame:CGRectMake(66, 117 ,189, 128)];

[mpc play];

}

 

Stop Button Code

- (IBAction)Stop:(id)sender {
[mpc stop];
[mpc.view removeFromSuperview];
[self.navigationController popViewControllerAnimated:YES];

}