Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS MPMoviePlayerViewController Loading endlessly

I'm working on a IOS App (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 a "Loading..." that takes forever. enter image description here

like image 628
luca Avatar asked Apr 08 '13 20:04

luca


1 Answers

You should call -prepareToPlay and/or -play. Per MPMoviePlayerController's documentation:

Starting in iOS 5.0, in order to facilitate finer-grained playback control, a new movie player is not automatically prepared to play.

like image 173
zadr Avatar answered Nov 15 '22 12:11

zadr