Mathieu
Mathieu

Reputation: 3130

iPad MPMoviePlayerController - Disable Fullscreen

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

Upvotes: 14

Views: 18026

Answers (16)

diegomen
diegomen

Reputation: 1864

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)

Upvotes: 1

coolcool1994
coolcool1994

Reputation: 3804

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.

Upvotes: 0

Thiru
Thiru

Reputation: 1378

Fullscreen button along with pause button can be removed.

[self.videoPlayer setControlStyle:MPMovieControlStyleNone];

Upvotes: 2

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

Upvotes: 5

user1270061
user1270061

Reputation: 671

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.

Upvotes: 2

dOM
dOM

Reputation: 555

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

[_moviePlayerController setControlStyle:MPMovieControlStyleFullscreen];

Upvotes: 6

R Rungsikavanich
R Rungsikavanich

Reputation: 173

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

Upvotes: 2

Anthony Main
Anthony Main

Reputation: 6068

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

Upvotes: 5

Nigel Flack
Nigel Flack

Reputation: 108

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

Upvotes: 1

Nikita Ilyasov
Nikita Ilyasov

Reputation: 500

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

Upvotes: 0

Nim Gat
Nim Gat

Reputation: 650

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; 

Upvotes: 3

borisdiakur
borisdiakur

Reputation: 12072

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

Upvotes: 11

rgeorge
rgeorge

Reputation: 7327

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.

Upvotes: 4

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.

Upvotes: 2

Phil
Phil

Reputation: 2794

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

player.view.userInteractionEnabled = NO;

Upvotes: 7

Retterdesdialogs
Retterdesdialogs

Reputation: 3210

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

Upvotes: 3

Related Questions