0
NSURL *url="file:///Users/adi/Library/Developer/CoreSimulator/Devices/F7C9D729-6E67-45C3-9234-629460FDD0A4/data/Containers/Data/Application/319F0627-CF3E-43D4-A44F-3E5E797CCCEA/Library/Caches/Attachments/7157783VID_20150602_185133.mp4"

Here's my code:

MPMoviePlayerController * moviePlayer =[[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(10, 100, 300, 200);
[moviePlayer play];

It shows blank screen.

rmaddy
  • 314,917
  • 42
  • 532
  • 579

3 Answers3

0

Well if you have to play video using local file use this code.It is helpful for you.

NSString*thePath=[[NSBundle mainBundle] pathForResource:@"yourVideo" ofType:@"mp4"];//7157783VID_20150602_185133 name
NSURL*theurl=[NSURL fileURLWithPath:thePath];
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:theurl];
[moviePlayer.view setFrame:CGRectMake(10, 100, 200, 300)];
[moviePlayer prepareToPlay];
[moviePlayer setShouldAutoplay:NO]; // And other options you can look through the documentation.
[self.view addSubview:moviePlayer.view];

If you want to control playback process

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playBackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
user3182143
  • 9,459
  • 3
  • 32
  • 39
baydi
  • 1,003
  • 6
  • 11
0

Hope this may help you

#import<MediaPlayer/MediaPlayer.h>

-(IBAction)VideoPlayer:(id)sender
{
   NSString *path = [[NSBundle mainBundle]pathForResource: @"video-en-2b" ofType:@"mp4"];
   moviePlayer = [[MPMoviePlayerViewControlle alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
   Codin[self presentModalViewController:moviePlayer animated:NO];
}
user3182143
  • 9,459
  • 3
  • 32
  • 39
Akash Raghani
  • 557
  • 1
  • 9
  • 21
0

Try this :

-(void)playVideo : (NSString*)apath
{
    NSURL *videoURL =[NSURL fileURLWithPath:apath];

    if ([[NSFileManager defaultManager] fileExistsAtPath:apath])        //Does file exist?
    {
        MPMoviePlayerViewController *videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
        videoPlayerView.moviePlayer.movieSourceType=MPMovieSourceTypeFile;
        [self presentMoviePlayerViewControllerAnimated:videoPlayerView];
        [videoPlayerView.moviePlayer play];
    }
}

Note: this method only accept local file path

Parth Bhadaja
  • 416
  • 3
  • 15