iPad MPMoviePlayerController - 禁用全屏

发布于 2024-09-17 20:11:27 字数 45 浏览 4 评论 0原文

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

Is there a way to disable the fullscreen button of the MPMoviePlayerController ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(16

遗心遗梦遗幸福 2024-09-24 20:11:27

刚刚做了:

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

Just did it:

- (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];
}
断桥再见 2024-09-24 20:11:27

根据您的需要,您还可以简单地禁用播放器视图上的所有用户交互。

player.view.userInteractionEnabled = NO;

Depending on your needs, you can also simply disable all user interactions on the player view.

player.view.userInteractionEnabled = NO;
演出会有结束 2024-09-24 20:11:27

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

[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];

You can set controlStyle to Fullscreen. these controls are somewhat different, but it doesn't feature a Fullscreen button!

[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];
有深☉意 2024-09-24 20:11:27

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

[player setMovieControlMode:MPMovieControlModeNone];

You could hide the playback controls and add your own custom ones, this will prevent the default buttons being rendered at all

I.e with

[player setMovieControlMode:MPMovieControlModeNone];
维持三分热 2024-09-24 20:11:27

不幸的是,以上内容都不适合我,因此选择上面的内容我实现了以下内容(并且工作正常):

  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!!!
    }

Unfortunately none of above worked for me properly, so picking the above I implemented the following (and worked fine):

  1. Hide the full screen button.

Add this code in the method where you initialise the movie player.

    ....

        //Because we have to wait until controllers are shown

        [self performSelector:@selector(hideFullscreenButton) withObject:self afterDelay:0.5];

    ...

Add the methods:

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

            }

        }

    }

The problem relies that there is no tag to identify which view you have to hide. In my case I figure it out by the view coordinates.

  1. Overwrite tap gestures for do not allowing fullscreen zoom.
 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];

And add the selector methods:

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

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

飘然心甜 2024-09-24 20:11:27

有一个作弊:

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

主要的问题是,您必须在 viewDidAppear: 或类似的位置执行此操作,因为 MoviePlayer 视图会在 didMoveToWindowdidMoveToSuperview< 内部的某个位置进行设置/code>,发生在 viewWillAppear: 之后。因此,您会看到全屏按钮的短暂闪烁。其他明显的问题包括: brittle 与 Apple 更改 512 标签值(尽管它在 3.2 - 4.2 中有效);当然,苹果不希望你这样做。

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

There's a cheat:

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

The main catch is, you have to do it in viewDidAppear: or similar, because the MoviePlayer view sets itself up somewhere inside didMoveToWindow or didMoveToSuperview, which happen after viewWillAppear:. So you get a brief flash of the fullscreen button. Other obvious catches include: brittle vs. Apple changing that 512 tag value (although it works in 3.2 - 4.2); and of course Apple would rather you not do this.

The endorsed solution is to set the control style to MPMovieControlStyleNone and roll your own transport controls, which is more work.

Oo萌小芽oO 2024-09-24 20:11:27

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

No, there is no way. Hopefully with the next update.

我是有多爱你 2024-09-24 20:11:27

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

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

in order to disable switch to full screen mode, either form button or pinch gesture, you can use this:

moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.view.userInteractionEnabled =NO; 
半步萧音过轻尘 2024-09-24 20:11:27

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

Wired does this. For the videos that start in fullscreen, they have the standard MPMoviePlayerController controls, but are missing the fullscreen buttons. And they're using the standard built-in ones, since they suddenly got an AirPlay button with 4.2.

顾忌 2024-09-24 20:11:27

在这里删除捏缩放的简单块

希望它能帮助

我在 iOS6 上工作

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

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

Simple block to remove pinch zoom here

Hope it help

it work with me on iOS6

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

    for(UIPinchGestureRecognizer *pinch in view.gestureRecognizers){
    if([pinch isKindOfClass:[UIPinchGestureRecognizer class]])
        [view removeGestureRecognizer:pinch];
    }
}
也只是曾经 2024-09-24 20:11:27

这适用于 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”时,它导致黑屏,没有控件。发生转换时会出现轻微的故障,但我需要嵌入的播放/滑动按钮。

This worked on 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;
    }
}

Notice that I only listen for "DID" and not the "WILL" notification as well as running it animated. I think this works as it gives the system time to react. When I used the "WILL" and "DID" as noted in answers above it led to a black screen with no controls. There is a slight glitch that is visible when the transition occurs, but I need the play/scrub buttons from embedded.

只怪假的太真实 2024-09-24 20:11:27

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

[self.videoPlayer setControlStyle:MPMovieControlStyleNone];

Fullscreen button along with pause button can be removed.

[self.videoPlayer setControlStyle:MPMovieControlStyleNone];
好菇凉咱不稀罕他 2024-09-24 20:11:27

如果您想要做的唯一事情是禁用捏合以全屏显示(即保持交互启用以及您想要的任何控制样式),您可以使用以下命令:

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

If the only thing you want to do is disable pinch to go full screen (i.e. keep interaction enabled and whatever control style you want), you can use this:

- (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;
            }
        }
    }
}
饮湿 2024-09-24 20:11:27

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

当用户点击 Play 时:

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

(VideoViewController 是我在其中拥有 MPMoviePlayerController 的视图控制器)

This is the Swift version of the first solution of Javier Calatrava Llavería:

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

And when the user taps on Play:

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

(VideoViewController is the view controller in which I have the MPMoviePlayerController)

难得心□动 2024-09-24 20:11:27

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

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

I know, it's a little outdated, but anyway. I did some research in that direction, and looks like a found an answer. I do not know, why it's working, but it is.

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

// When the movie is done, release the controller.

-(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:
}
何以畏孤独 2024-09-24 20:11:27

将具有透明背景的 UIViewUIButton 放置在显示视频的视图顶部,以便用户无法点击包含视频的视图。

Put a UIView or UIButton with transparent background on top of the view that shows the video, so that the user won't be able to tap on the view that contains the video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文