Reputation: 21593
I am playing a movie via:
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];
//[[vc moviePlayer] prepareToPlay];
[self presentViewController:moviePlayer animated:YES completion:NULL];
The controller shows up but immediately after, dismisses itself. What am I doing wrong? Thanks!
Upvotes: 0
Views: 1523
Reputation: 11696
Had a similar issue while trying to play audio. Try setting your movie player as a property with a strong reference.
Upvotes: 1
Reputation: 21593
From the docs:
" To present a movie player view controller modally, you typically use the presentMoviePlayerViewControllerAnimated:
method. This method is part of a category on the UIViewController
class and is implemented by the Media Player framework. The presentMoviePlayerViewControllerAnimated:
method presents a movie player view controller using the standard transition animations for presenting video content. To dismiss a modally presented movie player view controller, call the dismissMoviePlayerViewControllerAnimated
method."
You can't use the normal modal presentation method. Must use the method provided by media player framework in UIViewContoller
category.
Upvotes: 0
Reputation: 49730
you have to remove MPMoviePlayerPlaybackDidFinishNotification
NSNotificationCenter
like :-
moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:asset.filepath]];
//[[vc moviePlayer] prepareToPlay];
[[NSNotificationCenter defaultCenter] removeObserver:moviePlayer name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer.moviePlayer];
[self presentViewController:moviePlayer animated:YES completion:NULL];
Becouse MPMoviePlayerViewController
automatically registers itself to the NSNotificationCenter
upon creation. You have to first remove this registration and it will stop dismissing itself automatically. Hope its helps you
Please check Bellow Link:-
http://josebolanos.wordpress.com/2011/09/28/dismissing-mpmovieplayerviewcontroller-the-right-way/
Upvotes: 2
Reputation: 6524
Check your -(void)viewWillDisappear:(BOOL)animated{
method, if you are dismissing
your moviePlayer
then this is the reason.
Upvotes: 0