MPMoviePlayerController 播放器在按下完成按钮后永久隐藏播放器控件。
我有一个带有moviePlayer.controlStyle = MPMovieControlStyleEmbedded的嵌入式播放器,当用户在moviePlayerDidEnterFullscreen通知中点击全屏模式时,我正在制作[moviePlayer setFullscreen:NO];并将播放器视频转换为横向模式
moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
和设置
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
然后,当我点击完成按钮并在 moviePlayBackDidFinish 中,我将视图转换回纵向模式并将 controlStyle 设置为 Embedded。到目前为止,它工作正常。之后该视频将暂停,当我点击播放按钮时,它开始播放,播放器将停留一段时间并永久隐藏。点击视频后,播放器将不再可见。我尝试在延迟后将播放器控件设置为嵌入。但没有任何工作。请帮助解决这个问题。
此问题仅在 iOS 6 以下版本中出现
代码
[[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];