Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController showing black empty screen

I use MPMoviePlayerController to play a local file in my Application Document folder which have I have downloaded for a server URL:

itemMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
 [self.view addSubview:itemMoviePlayerController.view];
 itemMoviePlayerController.fullscreen = YES;
 itemMoviePlayerController.movieSourceType = MPMovieSourceTypeFile;
 itemMoviePlayerController.initialPlaybackTime = -1.0;
 [itemMoviePlayerController play];

When I play .mov file just after I downloaded it, It shows up a black empty screen & app UI is unusable. But if play same local file next time, it plays fine. I even verified playState & localState for MPMoviePlayerController they seems fine. What could be reason for black empty screen?

like image 438
Ritika Avatar asked Dec 08 '11 10:12

Ritika


4 Answers

You need to retain your instance of MPMoviePlayerController i.e. as a property or an instance variable. The reference to the movie player is lost if you do not retain it.

like image 188
Toms Shaji Mathew Avatar answered Nov 20 '22 13:11

Toms Shaji Mathew


You could try to put [itemMoviePlayerController prepareToPlay]; before the [itemMoviePlayerController play];

The way preferred by Apple to display an only full screen video is to present a modal MPMoviePlayerViewController (as Hollance said). To present it, you should use something like :

 moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
 [self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
 [itemMoviePlayerController play];

This is documented by Apple here

You can read there that you should keep a reference to your MPMoviePlayerViewController in order to dismiss it later with

[self dismissMoviePlayerViewControllerAnimated:moviePlayerViewController].

like image 41
dulgan Avatar answered Nov 20 '22 13:11

dulgan


I fixed this by putting

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer; 

in my .h file, and calling self.moviePlayer in all my code and it worked!

like image 13
mattblessed Avatar answered Nov 20 '22 13:11

mattblessed


You need to use MPMoviePlayerViewController instead. Notice the word "View" in there.

like image 7
Hollance Avatar answered Nov 20 '22 12:11

Hollance