美文网首页
webview内的MPMoviePlayerController

webview内的MPMoviePlayerController

作者: 简书笔记存档 | 来源:发表于2016-06-29 15:02 被阅读0次

应项目要求,播放器要实现全屏之后横屏,查找半天资料终于找到相应的资料
资料源:http://www.jianshu.com/p/deecfa886dac
实现方法:
在appdelegate页面:
.h
@property(nonatomic)BOOL allowRotation;
.m

pragma mark ------------ MediaPlayer选择全屏模式

实现以下方法

  • (void)addMoviePlaybackRotateNotification{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
    }
  • (void) moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = YES;
    }
  • (void) moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
    self.allowRotation = NO;
    }

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (self.allowRotation) {
项目要求直接横屏,所以我只选择一个方向。
return UIInterfaceOrientationMaskLandscapeRight;
}
return UIInterfaceOrientationMaskPortrait;
}

现在就可以实现全屏啦

相关文章

网友评论

      本文标题:webview内的MPMoviePlayerController

      本文链接:https://www.haomeiwen.com/subject/jtlxjttx.html