I may not have worded my title very well, maybe more correct to say my NSNotification isn't dismissing my movie's view after it's done playing. I've found others with this problem but no solutions, seems like it might be a problem with iOS 6 which is what I'm running.
After the video is done playing, you need to press "Done" to dismiss but I want it to dismiss automatically since I will be using MPMovieControlStyleNone once I get this sorted out. Here's my code with the unused sections stripped out: `
#import "MovieViewController.h"
@interface MovieViewController ()
@end
@implementation MovieViewController
@synthesize moviePlayer = _moviePlayer;
- (IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"TestMovie" ofType:@"mov"]];
_moviePlayer =
[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:NO];
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
if ([player
respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}
@end`
Had this problem as well To fix in moviePlayBackDidFinish just add
player.fullscreen = NO;
before removing view from superview
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