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!
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/
Had a similar issue while trying to play audio. Try setting your movie player as a property with a strong reference.
检查您的-(void)viewWillDisappear:(BOOL)animated{
方法,如果您要dismissing
moviePlayer
那么这就是原因。
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.