Anhayt Ananun
Anhayt Ananun

Reputation: 896

MPMoviePlayerController do not load movie

I want to play video in my iPad app, using MPMoviePlayerController. My problem is, that player is only displaying "Loading" and do not play the video. Here is the code I use:

- (void)playMovieFile:(NSString *)fileName
{
    NSString *filePath=[[NSBundle mainBundle] pathForResource:fileName ofType:@"mov"];
    NSURL *fileUrl=[NSURL fileURLWithPath:filePath];

    self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:fileUrl];
    [self.moviePlayer.view setFrame:self.view.frame];

    [self.view addSubview:self.moviePlayer.view];
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer play];
}

I also try to use MPMoviePlayerViewController, but with sane success.Also, what movie types do MPMoviePlayerController plays? Can it be because of size of movie? It is 263 MB.

Upvotes: 2

Views: 3465

Answers (1)

nsgulliver
nsgulliver

Reputation: 12671

The movie formats supported on the iPhone are .mov, .m4v, mp4 or 3gp.

The video technologies in iOS support the playback of movie files with the .mov, .mp4, .m4v, and .3gp filename extensions and using the following compression standards:

In Case you playing the movie with above mentioned extensions then. declare your MPMoivePlayer as class type property in your .h class

@property(strong,nonatomic)MPMoviePlayerController *moviePlayer;

in your .m

NSString *filePath=[[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"mov"];

NSURL *fileUrl=[NSURL fileURLWithPath:filePath];

self.moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:fileUrl];
[self.moviePlayer.view setFrame:CGRectMake(x,y,width,height)];

[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];

Upvotes: 5

Related Questions