gpt4 book ai didi

iphone - MPMoviePlayerController : Player hides Player Controls permenantly only in blow iOS6

转载 作者:可可西里 更新时间:2023-11-01 03:59:30 27 4
gpt4 key购买 nike

MPMoviePlayerController 播放器在按下完成按钮后永久隐藏播放器控件。

我有一个带有 moviePlayer.controlStyle = MPMovieControlStyleEmbedded 的嵌入式播放器,当用户在 moviePlayerDidEnterFullscreen 通知中点击全屏模式时,我正在制作 [moviePlayer setFullscreen:NO];并将播放器视频转换为横向模式

moviePlayer.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));

和设置

moviePlayer.controlStyle =  MPMovieControlStyleFullscreen; 

然后,当我点击完成按钮并在 moviePlayBackDidFinish 中时,我将 View 转换回纵向模式并将 controlStyle 设置为嵌入式。到目前为止它工作正常。该视频将暂停后,当我点击播放按钮时,它开始播放,播放器将停留一段时间并永久隐藏。点击视频后播放器将不再可见。我试图在延迟后将播放器控制设置为嵌入。但没有任何效果。请帮助解决这个问题。

此问题仅存在于 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];

最佳答案

您的代码有点错误并触发了那些 MPMoviePlayerController 错误。

  • 多余的 setFullscreen 因为我们已经处于全屏状态。
  • 多余的 setControlStyle,因为我们已经在控制样式全屏中了

一般来说,您不应该在 MPMoviePlayerController 上强制执行已经完成的事情。

- (void)moviePlayerDidEnterFullscreen :(NSNotification*)notification 
{
//
//remove both lines from this notification handler
//
[mpVideoPlayerController.moviePlayer setFullscreen:NO];
[self performSelector:@selector(setControlStyleFullscreen) withObject:nil afterDelay:0.2];
[...]
}

您也可以通过检查当前模式来扩展您的 setControlStyleFullscreen/Embedded 实现。这可能看起来很奇怪,但确实有很大帮助。

- (void)setControlStyleEmbedded
{
if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleEmbedded)
{
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
}
}

- (void)setControlStyleFullscreen
{
if (mpVideoPlayerController.moviePlayer.controlStyle != MPMovieControlStyleFullscreen)
{
mpVideoPlayerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
}
}

关于iphone - MPMoviePlayerController : Player hides Player Controls permenantly only in blow iOS6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13971095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com