MPMoviePlayerController Player hides Player Controls permenantly after pressing done button.
I have a Embedded player with moviePlayer.controlStyle = MPMovieControlStyleEmbedded, and when user tap on full screen mode in moviePlayerDidEnterFullscreen notification i am making [moviePlayer setFullscreen:NO]; and transform the player video to Landscape mode
moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
and setting
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
Then when i tap on done button and in moviePlayBackDidFinish i am transforming the view back to Portrait mode and setting controlStyle to Embedded. So far its working fine. After that video will be paused and when i tap on play button its start play and player will stay for a while and hides for permanently. player no longer will be visible after taping on video. i tried to set player control to embedded after a delay. but nothing is working. Please help in this issue.
This issues is only in version below iOS 6
Code
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerDidEnterFullscreen:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:nil];
if (mpVideoPlayerController)
{
[mpVideoPlayerController.moviePlayer pause];
[mpVideoPlayerController.moviePlayer stop];
}
mpVideoPlayerController = nil;
mpVideoPlayerController = [[VideoPlayerViewController alloc] initWithContentURL: theURL];
mpVideoPlayerController.moviePlayer.movieSourceType = liveStreaming ? MPMovieSourceTypeStreaming : MPMovieSourceTypeUnknown;
if ([mpVideoPlayerController.moviePlayer respondsToSelector:@selector(setAllowsAirPlay:)]) {
mpVideoPlayerController.moviePlayer.allowsAirPlay = YES;
}
[[mpVideoPlayerController.moviePlayer view] setFrame:viewInsetRect];
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
mpVideoPlayerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
[viewController.view addSubview: [mpVideoPlayerController.moviePlayer view]];
[mpVideoPlayerController.moviePlayer play];
}
-(void) moviePlayerDidEnterFullscreen :(NSNotification*)notification {
[mpVideoPlayerController.moviePlayer setFullscreen:NO];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
[self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2];
[UIView animateWithDuration:0.3
animations:^{
mpVideoPlayerController.moviePlayer.view.transform = CGAffineTransformIdentity;
mpVideoPlayerController.moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
CGRect frame=[[UIScreen mainScreen] applicationFrame];
frame.origin.y=-20;
mpVideoPlayerController.moviePlayer.view.frame = frame;//CGRectMake(0.0, 0.0, 480.0, 300.0);
} completion:^(BOOL finished) {
}];
}
- (void) setControlStyleFullscreen
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
- (void) setControlStyleEmbedded
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
- moviePlayBackDidFinish:
NSLog(@"moviePlayBackDidFinish:");
[self rotateToInterfaceOrientation:UIInterfaceOrientationPortrait frameForView:(viewController).videoContentView.frame];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[self performSelector:@selector(setControlStyleEmbedded) withObject:nil afterDelay:0.2];
Your code is kind of faulty and triggers those MPMoviePlayerController
bugs.
Generally speaking, you should never enforce things on MPMoviePlayerController that are already done.
- (void)moviePlayerDidEnterFullscreen :(NSNotification*)notification
{
//
//remove both lines from this notification handler
//
[mpVideoPlayerController.moviePlayer setFullscreen:NO];
[self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2];
[...]
}
You may as well extend your setControlStyleFullscreen / Embedded implementation by checking for the current mode. That may seem weird but it does help a lot.
- (void)setControlStyleEmbedded
{
if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleEmbedded)
{
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}
}
- (void)setControlStyleFullscreen
{
if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleFullscreen)
{
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
}
}
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