iPad MPMoviePlayerController - 禁用全屏

时间:2010-09-06 09:27:45

标签: ipad ios mpmovieplayercontroller fullscreen

有没有办法禁用MPMoviePlayerController的全屏按钮?

16 个答案:

答案 0 :(得分:11)

刚刚做到了:

- (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];
}

答案 1 :(得分:7)

根据您的需要,您还可以在播放器视图上禁用所有用户互动。

player.view.userInteractionEnabled = NO;

答案 2 :(得分:6)

您可以将controlStyle设置为Fullscreen。这些控件有些不同,但它没有全屏按钮!

[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];

答案 3 :(得分:5)

您可以隐藏播放控件并添加自己的自定义控件,这样可以防止默认按钮被渲染

I.e with

[player setMovieControlMode:MPMovieControlModeNone];

答案 4 :(得分:5)

不幸的是,上面没有一个对我有用,所以选择上面我实现了以下(并且工作正常):

  1. 隐藏全屏按钮。
  2. 在初始化电影播放器​​的方法中添加此代码。

    
        ....
    
            //Because we have to wait until controllers are shown
    
            [self performSelector:@selector(hideFullscreenButton) withObject:self afterDelay:0.5];
    
        ...
    
    

    添加方法:

    
        -(void) hideFullscreenButton{
    
            //Hide full screen mode button
    
            [self hideFullscreenSubview:movieClip.view.subviews];
    
        }
    
    
    
        -(void) hideFullscreenSubview:(NSArray*)arr{
    
            for(UIView *v in arr){
    
                if([v.subviews count]>0)
    
                    [self hideFullscreenSubview:v.subviews];
    
                else
    
                    NSLog(@"%@",v);
    
                if(v.frame.origin.x==975 ){
    
                    v.hidden=TRUE;
    
                }
    
            }
    
        }
    
    

    问题依赖于没有标记来标识您必须隐藏哪个视图。在我的情况下,我通过视图坐标来计算它。

    1. 覆盖点按手势,不允许全屏缩放。
    2. 
       movieClip.controlStyle = MPMovieControlStyleEmbedded;    
      
          //Disable tap for not allowing that video control set on a full screen mode.
          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];
      
      

      并添加选择器方法:

      
          -(void) doSingleTap{
              //DO NOTHING!!!
          }
      
          -(void) doDoubleTap{
              //DO NOTHING!!!
          }
      
      

答案 5 :(得分:4)

有一个骗子:

MPMoviePlayerController *mpc = (...some instance...)
UIView *fsbutton = [[mpc view] viewWithTag:512];
[fsbutton setHidden:YES];

主要问题是,您必须在viewDidAppear:或类似内容中执行此操作,因为MoviePlayer视图会将自己设置在didMoveToWindowdidMoveToSuperview内的某个位置,这发生在{{1}之后}。因此,您可以快速浏览全屏按钮。其他明显的捕获量包括:脆弱对比苹果改变512标签值(尽管它在3.2 - 4.2中工作);当然,Apple宁愿你不要这样做。

认可的解决方案是将控件样式设置为viewWillAppear:并滚动您自己的传输控件,这是更多的工作。

答案 6 :(得分:3)

不,没有办法。希望下次更新。

答案 7 :(得分:3)

为了禁用切换到全屏模式,无论是表单按钮还是捏合手势,都可以使用:

moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.userInteractionEnabled =NO; 

答案 8 :(得分:2)

有线这样做。对于以全屏方式启动的视频,它们具有标准的MPMoviePlayerController控件,但缺少全屏按钮。他们使用的是标准内置扬声器,因为他们突然得到一个4.2的AirPlay按钮。

答案 9 :(得分:2)

可以删除全屏按钮和暂停按钮。

[self.videoPlayer setControlStyle:MPMovieControlStyleNone];

答案 10 :(得分:2)

在此处移除捏缩放的简单块

希望有所帮助

它在iOS6上与我合作

 for (UIView *view in  moviePlayer.view.subviews) {

    for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
    if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
        [view removeGestureRecognizer:pinch];
    }
}

答案 11 :(得分:2)

适用于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”时,它会导致黑屏无法控制。转换发生时会出现轻微的故障,但我需要嵌入式播放/清理按钮。

答案 12 :(得分:1)

如果您要执行的事情是禁用全部屏幕捏合(即启用交互功能以及您想要的任何控件样式),您可以使用此功能:

- (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;
            }
        }
    }
}

答案 13 :(得分:1)

这是JavierCalatravaLlaverí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
        }
    }
}

当用户点击Play:

self.performSelector(#selector(VideoViewController.hideFullScreenButton), withObject: self, afterDelay: 0.5)

(VideoViewController是我有MPMoviePlayerController的视图控制器)

答案 14 :(得分:0)

我知道,它有点过时,但无论如何。我在那方面做了一些研究,看起来像找到了答案。我不知道,为什么它有效,但确实如此。

-(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:
}

答案 15 :(得分:0)

在显示视频的视图顶部放置一个透明背景的Refused to display 'https://www.reddit.com/live/veh2e41lp0he' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'UIView,以便用户无法点按包含视频的视图。