IOS MPMoviePlayerViewController Download endlessly

I am working on an iOS application (with Storyoard). I have a ViewController:

//movieViewController.h #import <UIKit/UIKit.h> #import <MediaPlayer/MediaPlayer.h> @interface movieViewController : UIViewController { MPMoviePlayerViewController *moviePlayer; } @property (strong, nonatomic) MPMoviePlayerViewController *moviePlayer; -(void) playMovie; @end //movieViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. [self playMovie]; } -(void)playMovie { NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"mov"]; moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]]; [self presentMoviePlayerViewControllerAnimated:moviePlayer]; } 

When I run, I see my viewController with "Loading ...", which takes forever. enter image description here

+7
source share
2 answers

You must call -prepareToPlay and / or -play . Per MPMoviePlayerController documentation:

Starting with iOS 5.0, the new movie player will not be automatically prepared for the game to simplify the management of thinner playback.

+1
source
  - (IBAction) startVideo: (id) sender
 {
     NSURL * video = [[NSURL alloc] initWithString: @ "http://www.w3schools.com/html/movie.mp4"];
     MPMoviePlayerViewController * controller = [[MPMoviePlayerViewController alloc] initWithContentURL: video];
     controller.view.frame = CGRectMake (20, 50, 280, 180);

     controller.moviePlayer.view.center = self.view.center;
     [self.view addSubview: controller.view];

     [controller.moviePlayer prepareToPlay];
     [controller.moviePlayer play];
 } 
0
source

All Articles