Reputation: 896
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
Reputation: 12671
The movie formats supported on the iPhone are .mov, .m4v, mp4 or 3gp
.
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