uttam
uttam

Reputation: 1364

How to play video locally in objective-c for iphone?

I want to play the video on iphone locally by storing the video in the app. how can i do?

Upvotes: 6

Views: 23149

Answers (4)

sash
sash

Reputation: 8715

FYI

The MPMoviePlayerController class is formally deprecated in iOS 9. (The MPMoviePlayerViewController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit.

Upvotes: 0

Ravi
Ravi

Reputation: 41

Try the following code:

-(IBAction)Videoplay_btn:(id)sender
{
   NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"m4v"];
   NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
   MPMoviePlayerController *moviplayer =[[MPMoviePlayerController alloc] initWithContentURL:     streamURL];
   [moviplayer prepareToPlay];
   [moviplayer.view setFrame: self.view.bounds];
   [self.view addSubview: moviplayer.view];
   moviplayer.fullscreen = YES;
   moviplayer.shouldAutoplay = YES;
   moviplayer.repeatMode = MPMovieRepeatModeNone;
   moviplayer.movieSourceType = MPMovieSourceTypeFile;
  [moviplayer play];        
}

Upvotes: 4

Kemo
Kemo

Reputation: 488

NSString *path = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];   

MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];

Upvotes: 11

Chuck
Chuck

Reputation: 237010

To store video in the app, you can just add it with a copy files phase in the build. For an example of how to play a movie, check out the Media Player docs and especially the MoviePlayer sample code.

Upvotes: 9

Related Questions