Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController Not playing Local file

 NSString *path = [[NSBundle mainBundle] pathForResource:@"PTCL" ofType:@"mp4"];    
  NSURL *videoURL = [NSURL URLWithString:path];    
        MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];    
        [moviePlayerController.view setFrame:self.view.frame];
        [self.view addSubview:moviePlayerController.view]; 
        moviePlayerController.controlStyle=MPMediaTypeAnyVideo;
        moviePlayerController.fullscreen = YES;
        [moviePlayerController prepareToPlay];
        [moviePlayerController play];

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

path=[NSString stringWithFormat:@"file:/%@",path];   
NSURL *videoURL = [NSURL URLWithString:path];

MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

[moviePlayerController.view setFrame:self.view.frame];
[self.view addSubview:moviePlayerController.view];

moviePlayerController.shouldAutoplay=YES;
moviePlayerController.controlStyle=MPMediaTypeAnyVideo;
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];

  • file:///Users/utkal/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/F0B3AD63-7E46-4069-8845-8B0C05425CD2/CosMos.app/PTCL.mp4

I am getting this videURL path for first code

  • file:///Users/utkal/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/F0B3AD63-7E46-4069-8845-8B0C05425CD2/CosMos.app/PTCL.mp4

I am getting this videURL path for second code.

I have alos use

NSURL *videoURL = [[NSURL alloc]init];
    videoURL = [[NSBundle mainBundle] URLForResource:@"PTCL" withExtension:@"mp4"];

But my video player always show that file is loading and nothing happen. I know some where I am doing mistake,but hard luck of mine. please correct my mistake or tell me if any another way to play local video file.Please.

enter image description here

like image 974
utkal patel Avatar asked Jan 17 '14 03:01

utkal patel


2 Answers

maybe is too late but i would try something like:

MPMoviePlayerViewController *movieVC = [[MPMoviePlayerViewController alloc] initWithContentURL:file.location];
movieVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
movieVC.moviePlayer.fullscreen = YES;
movieVC.moviePlayer.allowsAirPlay = YES;
movieVC.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentMoviePlayerViewControllerAnimated:movieVC];

notice the "movieVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;"

like image 157
Head_Worx Avatar answered Sep 19 '22 01:09

Head_Worx


I used this simple solution instead:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]];
MPMoviePlayerViewController* viewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:viewController];
like image 22
user623396 Avatar answered Sep 18 '22 01:09

user623396