【发布时间】:2011-04-08 16:46:33
【问题描述】:
有没有办法禁用 MPMoviePlayerController 的全屏按钮?
【问题讨论】:
标签: ipad ios mpmovieplayercontroller fullscreen
有没有办法禁用 MPMoviePlayerController 的全屏按钮?
【问题讨论】:
标签: ipad ios mpmovieplayercontroller fullscreen
不,没有办法。希望下次更新。
【讨论】:
您可以隐藏播放控件并添加自己的自定义控件,这将完全阻止呈现默认按钮
即与
[player setMovieControlMode:MPMovieControlModeNone];
【讨论】:
根据您的需要,您还可以简单地禁用播放器视图上的所有用户交互。
player.view.userInteractionEnabled = NO;
【讨论】:
有线就是这样做的。对于以全屏方式开始的视频,它们具有标准的 MPMoviePlayerController 控件,但缺少全屏按钮。他们正在使用标准的内置按钮,因为他们突然有了 4.2 的 AirPlay 按钮。
【讨论】:
有一个作弊:
MPMoviePlayerController *mpc = (...some instance...)
UIView *fsbutton = [[mpc view] viewWithTag:512];
[fsbutton setHidden:YES];
主要的问题是,你必须在viewDidAppear: 或类似的地方进行,因为MoviePlayer 视图设置在didMoveToWindow 或didMoveToSuperview 内部的某个位置,这发生在viewWillAppear: 之后。因此,您会短暂闪烁全屏按钮。其他明显的问题包括:脆性与 Apple 更改 512 标签值(尽管它适用于 3.2 - 4.2);当然,Apple 不希望你这样做。
认可的解决方案是将控件样式设置为MPMovieControlStyleNone 并滚动您自己的传输控件,这样工作量更大。
【讨论】:
刚刚做到了:
- (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];
}
【讨论】:
可以删除全屏按钮和暂停按钮。
[self.videoPlayer setControlStyle:MPMovieControlStyleNone];
【讨论】:
为了禁用切换到全屏模式,无论是表单按钮还是捏合手势,您都可以使用:
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.userInteractionEnabled =NO;
【讨论】:
我知道,它有点过时了,但无论如何。我朝那个方向做了一些研究,看起来像是找到了答案。我不知道为什么它会起作用,但确实如此。
-(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:
}
【讨论】:
如果您想要做的唯一事情是禁用捏合以全屏显示(即保持启用交互和您想要的任何控制样式),您可以使用这个:
- (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;
}
}
}
}
【讨论】:
这里删除捏缩放的简单块
希望对你有帮助
它适用于 iOS6
for (UIView *view in moviePlayer.view.subviews) {
for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
[view removeGestureRecognizer:pinch];
}
}
【讨论】:
您可以将 controlStyle 设置为全屏。这些控件有些不同,但没有全屏按钮!
[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
【讨论】:
这适用于 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”通知以及运行它的动画。我认为这很有效,因为它让系统有时间做出反应。当我使用上面答案中提到的“WILL”和“DID”时,它会导致没有控件的黑屏。发生过渡时会出现轻微故障,但我需要嵌入式播放/擦洗按钮。
【讨论】:
不幸的是,以上都不适用于我,所以选择以上我实现了以下(并且工作正常):
在初始化电影播放器的方法中添加此代码。
…… //因为我们必须等到控制器显示出来 [self performSelector:@selector(hideFullscreenButton) withObject:self afterDelay:0.5]; ...添加方法:
-(无效)隐藏全屏按钮{ //隐藏全屏模式按钮 [self hideFullscreenSubview:movieClip.view.subviews]; } -(void) hideFullscreenSubview:(NSArray*)arr{ for(UIView *v in arr){ if([v.subviews count]>0) [self hideFullscreenSubview:v.subviews]; 别的 NSLog(@"%@",v); 如果(v.frame.origin.x==975){ v.hidden=真; } } }问题在于没有标签来标识您必须隐藏哪个视图。就我而言,我是通过视图坐标来计算的。
并添加选择器方法:
-(无效)doSingleTap{ //没做什么!!! } -(无效)doDoubleTap{ //没做什么!!! }【讨论】:
在显示视频的视图顶部放置一个带有透明背景的UIView 或UIButton,这样用户将无法点击包含视频的视图。
【讨论】:
这是 Javier Calatrava Llavería 的第一个解决方案的 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
}
}
}
当用户点击播放时:
self.performSelector(#selector(VideoViewController.hideFullScreenButton), withObject: self, afterDelay: 0.5)
(VideoViewController 是我拥有 MPMoviePlayerController 的视图控制器)
【讨论】: