iPad MPMoviePlayerController – 禁用全屏
有没有办法来禁用MPMoviePlayerController的全屏button?
不,没有办法。 希望下次更新。
刚刚做到了:
- (void)viewDidLoad { [super viewDidLoad]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieEventFullscreenHandler:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieEventFullscreenHandler:) name:MPMoviePlayerDidEnterFullscreenNotification object:nil]; self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded; } - (void)movieEventFullscreenHandler:(NSNotification*)notification { [self.moviePlayer setFullscreen:NO animated:NO]; [self.moviePlayer setControlStyle:MPMovieControlStyleEmbedded]; }
根据您的需要,您还可以简单地禁用播放器视图中的所有用户交互。
player.view.userInteractionEnabled = NO;
您可以将controlStyle设置为全屏。 这些控件有些不同,但它不具有全屏button!
[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
您可以隐藏播放控件并添加自己的自定义控件,这将防止默认button被渲染
即与
[player setMovieControlMode:MPMovieControlModeNone];
不幸的是,上面没有一个适合我的工作,所以select上面我实现了以下(和工作正常):
- 隐藏全屏button。
在初始化电影播放器的方法中添加此代码。
.... //因为我们必须等到控制器显示 [self performSelector:@selector(hideFullscreenButton)withObject:self afterDelay:0.5]; ...
添加方法:
- (void)hideFullscreenButton { //隐藏全屏模式button [self hideFullscreenSubview:movieClip.view.subviews]; } - (void)hideFullscreenSubview:(NSArray *)arr { for(UIView * v in arr){ 如果([v.subviews count]> 0) [self hideFullscreenSubview:v.subviews]; 其他 的NSLog(@ “%@”,V); if(v.frame.origin.x == 975){ v.hidden = TRUE; } } }
这个问题依赖于没有标签来标识你必须隐藏哪个视图。 在我的情况下,我通过视图坐标来解决它。
- 改写轻击手势,不允许全屏缩放。
movieClip.controlStyle = MPMovieControlStyleEmbedded; //禁止点击,不允许在全屏模式下设置video控制。 UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doSingleTap)]; singleTap.numberOfTapsRequired = 1; [movieClip.view addGestureRecognizer:singleTap]; UITapGestureRecognizer * doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doDoubleTap)]; doubleTap.numberOfTapsRequired = 2; [movieClip.view addGestureRecognizer:doubleTap]; [singleTap requireGestureRecognizerToFail:doubleTap];
并添加select器方法:
- (void)doSingleTap { //没做什么!!! } - (void)doDoubleTap { //没做什么!!! }
有一个骗子:
MPMoviePlayerController *mpc = (...some instance...) UIView *fsbutton = [[mpc view] viewWithTag:512]; [fsbutton setHidden:YES];
主要的问题是,你必须在viewDidAppear:
或类似的地方做,因为MoviePlayer视图将自己设置在didMoveToWindow
或didMoveToSuperview
内部的某处,这发生在viewWillAppear:
之后viewWillAppear:
。 所以你可以简单的看一下全屏button。 其他明显的变化包括:脆弱与苹果改变512标签值(虽然它在3.2 – 4.2); 当然苹果公司宁愿你不要这样做。
批准的解决scheme是将控制样式设置为MPMovieControlStyleNone
并滚动您自己的传输控件,这是更多的工作。
为了禁用切换到全屏模式,无论是formsbutton还是捏手势,您都可以使用:
moviePlayer.controlStyle = MPMovieControlStyleNone; moviePlayer.view.userInteractionEnabled =NO;
有线这样做。 对于以全屏开始的video,它们具有标准的MPMoviePlayerController控件,但缺less全屏button。 而且他们使用标准的内置的,因为他们突然得到了4.2的AirPlaybutton。
简单的块在这里删除缩放
希望它有帮助
它在iOS6上与我一起工作
for (UIView *view in moviePlayer.view.subviews) { for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){ if([pinch isKindOfClass:[UIPinchGestureRecognizer class]]) [view removeGestureRecognizer:pinch]; } }
这适用于iOS 7,iPhone 5s。
Add Notification: MPMoviePlayerDidEnterFullscreenNotification : @"moviePlayFullscreenNote:" - (void)moviePlayFullscreenNote:(NSNotification*)notification { if (notification.object == self.videoPlayer) { [self.videoPlayer setFullscreen:NO animated:YES]; self.videoPlayer.controlStyle = MPMovieControlStyleEmbedded; } }
请注意,我只听“DID”而不是“WILL”通知,并运行animation。 我认为这是有效的,因为它给系统时间做出反应。 当我使用上面答案中提到的“WILL”和“DID”时,导致黑屏没有控制。 发生转换时会出现一些小故障,但是我需要embedded式播放/擦洗button。
全屏button和暂停button可以被删除。
[self.videoPlayer setControlStyle:MPMovieControlStyleNone];
如果你想做的唯一的事情是禁用捏全屏(即保持交互启用和任何你想要的控制风格),你可以使用这个:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSSet *set = [event allTouches]; NSArray *arr = [set allObjects]; for (int i = 0; i < arr.count; i++) { UITouch *touch = (UITouch *) [arr objectAtIndex:i]; NSArray *recognisers = touch.gestureRecognizers; for (UIGestureRecognizer *recogniser in recognisers) { if (recogniser.enabled && [recogniser isMemberOfClass:[UIPinchGestureRecognizer class]]) { recogniser.enabled = NO; } } } }
这是Javier CalatravaLlavería的第一个解决scheme的Swift版本:
func hideFullScreenButton() { self.hideFullScreenSubview((self.moviePlayerController?.view.subviews)!) } func hideFullScreenSubview(subviews: [UIView]) { for view: UIView in subviews { if view.subviews.count > 0 { self.hideFullScreenSubview(view.subviews) } if view.frame.origin.x == 631 { view.hidden = true } } }
当用户点击Play时:
self.performSelector(#selector(VideoViewController.hideFullScreenButton), withObject: self, afterDelay: 0.5)
(VideoViewController是我有MPMoviePlayerController的视图控制器)
我知道,这有点过时,但无论如何。 我在这方面做了一些研究,看起来像是find了答案。 我不知道,为什么它的工作,但它是。
-(void) playMovieAtURL: (NSURL*) theURL { MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc] initWithContentURL: theURL]; //That line is for ARC. Without it, it may not work. self.moviePlayer = theMovie; theMovie.scalingMode = MPMovieScalingModeAspectFill; theMovie.controlStyle = MPMovieControlStyleFullscreen; theMovie.repeatMode = MPMovieRepeatModeOne; //Here you'd better use your custom ViewController subclass, if you want autorotating and all that stuff. UIViewController * vc = [UIViewController new]; [vc.view addSubview:theMovie.view]; theMovie.fullscreen = YES; theMovie.view.frame = vc.view.bounds; vc.view = theMovie.view; [self presentModalViewController:vc animated:YES]; theMovie.fullscreen = YES; [theMovie prepareToPlay]; [theMovie play]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; }
//当电影完成时,释放控制器。
-(void) myMovieFinishedCallback: (NSNotification*) aNotification { [self dismissModalViewControllerAnimated:YES]; MPMoviePlayerController* theMovie = [aNotification object]; [[NSNotificationCenter defaultCenter] removeObserver: self name: MPMoviePlayerPlaybackDidFinishNotification object: theMovie]; [self.moviePlayer.view removeFromSuperview]; self.moviePlayer = nil; // Release the movie instance created in playMovieAtURL: }
将UIView
或UIButton
放置在显示video的视图的顶部,以便用户无法点击包含video的视图。