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?
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.
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]
.
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!
You need to use MPMoviePlayerViewController instead. Notice the word "View" in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With