代码之家  ›  专栏  ›  技术社区  ›  Mathieu Chirag patel

iPad MPMoviePlayerController-禁用全屏

  •  14
  • Mathieu Chirag patel  · 技术社区  · 14 年前

    16 回复  |  直到 14 年前
        1
  •  3
  •   Retterdesdialogs    14 年前

    不,不可能。希望下次更新。

        2
  •  11
  •   borisdiakur Faheel Khan    14 年前

    - (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];
    }
    
        3
  •  7
  •   Phil    14 年前

    player.view.userInteractionEnabled = NO;
    
        4
  •  6
  •   dOM    11 年前

    [_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
    
        5
  •  5
  •   Dhara    11 年前

    您可以隐藏播放控件并添加自己的自定义控件,这将完全阻止渲染默认按钮

    也就是说

    [player setMovieControlMode:MPMovieControlModeNone];
    
        6
  •  5
  •   Javier Calatrava Llavería    10 年前

    1. 隐藏全屏按钮。

    在初始化电影播放器的方法中添加此代码。

        ....
    
            //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. 覆盖不允许全屏缩放的点击手势。
     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!!!
        }
    
    
        7
  •  4
  •   rgeorge    14 年前

    有个骗子:

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

    viewDidAppear: 或者类似的,因为MoviePlayer视图设置在内部的某个地方 didMoveToWindow didMoveToSuperview ,发生在 viewWillAppear: . 所以你会看到全屏按钮的短暂闪光。其他明显的问题包括:脆性与苹果改变512标签值(尽管它在3.2-4.2中有效);当然苹果也不希望你这么做。

    认可的解决方案是将控件样式设置为 MPMovieControlStyleNone

        8
  •  3
  •   Nim Gat    13 年前

    要禁用切换到全屏模式,无论是窗体按钮还是捏手势,都可以使用以下命令:

    moviePlayer.controlStyle = MPMovieControlStyleNone;
    moviePlayer.view.userInteractionEnabled =NO; 
    
        9
  •  2
  •   Christian A. Strømmen    14 年前

    连线就是这样。对于以全屏开始的视频,它们有标准的MPMoviePlayerController控件,但缺少全屏按钮。他们使用的是标准的内置按钮,因为他们突然有了4.2的AirPlay按钮。

        10
  •  2
  •   R Rungsikavanich    11 年前

    希望有帮助

    它在iOS6上和我一起工作

     for (UIView *view in  moviePlayer.view.subviews) {
    
        for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
        if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
            [view removeGestureRecognizer:pinch];
        }
    }
    
        11
  •  2
  •   user1270061    11 年前

    这在iOS7、iPhone5s上奏效。

    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
  •  2
  •   Thiru    9 年前

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

    [self.videoPlayer setControlStyle:MPMovieControlStyleNone];
    
        13
  •  1
  •   Nigel Flack    12 年前

    只有 您要做的是禁用pinch to go全屏(即保持交互启用,以及您想要的任何控制样式),您可以使用以下方法:

    - (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;
                }
            }
        }
    }
    
        14
  •  1
  •   diegomen    8 年前

    这是Javier Calatrava-Llavera第一个解决方案的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的视图控制器)

        15
  •  0
  •   Nikita Ilyasov    12 年前

    我知道,有点过时了,但不管怎样。我在这方面做了一些研究,似乎找到了答案。我不知道,它为什么起作用,但它确实起作用了。

    -(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:
    }
    
        16
  •  0
  •   Julian E.    9 年前

    放一个 UIView UIButton