Enter and exit full screen (iOS)

Learn how to implement full-screen mode in the iOS SDK


Full-screen mode enables viewers to expand the player to fill up the entire device screen.

When using JWPlayerViewController or JWPlayerObjCViewController, full screen can be entered and exited in several ways.

ApproachDescription
AutomaticFull screen engaged automatically when device orientation changes from portait to landscape if forceFullScreenOnLandscape on JWPlayerViewController is true
ManualFull screen engaged by viewer tapping the full screen icon ( )
ProgrammaticFull screen engaged by calling transitionToFullScreen and dismissFullScreen methods on the view controller

πŸ“˜

If you are only using JWPlayerView, you must implement full screen capability yourself or display the view in full screen with your own interface.



Programmatically enter and exit full screen

The transitionToFullScreen and dismissFullScreen methods can be used on either the JWPlayerViewController or JWPlayerObjCViewController to enter and exit full screen programmatically.

The following recipe shows how to use these methods in a class that has a full-screen toggle to enter and exit full-screen mode.



transitionToFullScreen()

Transitions the player to full-screen mode

If the player is already in full-screen mode, this method does not perform any actions. The completion closer will not be executed.


public func dismissFullScreen(animated: Bool, completion: (() -> Void)? = nil)
- (void)dismissFullScreenAnimated:(BOOL)animated completion:(void (^)(void))completion;
ArgumentDescription
animatedΒ BoolDetermines if the player should animate into full screen
completionClosure called after the player has transitioned to full-screen mode

dismissFullScreen()

Transitions the player away from full-screen mode

If the player is not in full-screen mode this method does not perform any actions. The completion closure will not be executed.


public func transitionToFullScreen(animated: Bool, completion: (() -> Void)? = nil)
- (void)transitionToFullScreenAnimated:(BOOL)animated completion:(void (^)(void))completion;
ArgumentDescription
animatedΒ BoolDetermines if the player should animate away from full-screen mode
completionΒ ClosureClosure called after the player has transitioned away from full-screen mode


Respond to Full-Screen Events

There are several full screen events that you can respond to using JWPlayerViewControllerDelegate.

The following example shows a class conforming to JWPlayerViewControllerDelegate.

class CustomPlayerViewController: JWPlayerViewController, JWPlayerViewControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Set the JWPlayerViewControllerDelegate to self
        delegate = self
    }

    // MARK: - JWPlayerViewControllerDelegate

    func playerViewControllerWillGoFullScreen(_ controller: JWPlayerViewController) -> JWFullScreenViewController? {
        return nil
    }

    func playerViewControllerDidGoFullScreen(_ controller: JWPlayerViewController) {

    }

    func playerViewControllerWillDismissFullScreen(_ controller: JWPlayerViewController) {

    }

    func playerViewControllerDidDismissFullScreen(_ controller: JWPlayerViewController) {

    }
// CustomViewController.h
@interface CustomViewController : JWPlayerObjCViewController <JWPlayerViewControllerDelegate>

@end

// CustomViewController.m

@implementation CustomViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    // Set the JWPlayerViewControllerDelegate to self
    self.delegate = self;
}

#pragma mark JWPlayerViewControllerDelegate

- (JWFullScreenViewController * _Nullable)playerViewControllerWillGoFullScreen:(JWPlayerViewController * _Nonnull)controller {
    return nil;
}

- (void)playerViewControllerDidGoFullScreen:(JWPlayerViewController * _Nonnull)controller {
    
}

- (void)playerViewControllerWillDismissFullScreen:(JWPlayerViewController * _Nonnull)controller {
    
}

- (void)playerViewControllerDidDismissFullScreen:(JWPlayerViewController * _Nonnull)controller {
    
}


playerViewControllerWillGoFullScreen()

Called before the player is enlarged to the size of the screen

This method returns the JWFullScreenViewController that will be used for full screen. If nil is returned, the default JWFullScreenViewController will be used.


func playerViewControllerWillGoFullScreen(_ controller: JWPlayerViewController) -> JWFullScreenViewController? {
        return nil
    }
- (JWFullScreenViewController * _Nullable)playerViewControllerWillGoFullScreen:(JWPlayerViewController * _Nonnull)controller {
    return nil;
}
ArgumentDescription
controllerΒ JWPlayerViewerControllerJWPlayerViewController emitting the event

playerViewControllerDidGoFullScreen()

Called after the player has enlarged to the size of the screen


func playerViewControllerDidGoFullScreen(_ controller: JWPlayerViewController) {}
- (void)playerViewControllerDidGoFullScreen:(JWPlayerViewController * _Nonnull)controller {}
ArgumentDescription
controllerΒ JWPlayerViewerControllerJWPlayerViewController emitting the event

playerViewControllerWillDismissFullScreen()

Called before the player dismisses full screen, and shrinks back to its normal size


func playerViewControllerWillDismissFullScreen(_ controller: JWPlayerViewController) {}
- (void)playerViewControllerWillDismissFullScreen:(JWPlayerViewController * _Nonnull)controller {}
ArgumentDescription
controllerΒ JWPlayerViewerControllerJWPlayerViewController emitting the event

playerViewControllerDidDismissFullScreen()

Called after the player dismisses full screen, and shrinks back to its normal size


func playerViewControllerDidDismissFullScreen(_ controller: JWPlayerViewController) {}
- (void)playerViewControllerDidDismissFullScreen:(JWPlayerViewController * _Nonnull)controller {}
ArgumentDescription
controllerΒ JWPlayerViewerControllerJWPlayerViewController emitting the event


Customize the JWFullScreenController

πŸ“˜

JWFullScreenController is only customizable with JWPlayerViewController.

You have the option to use your own subclass of JWFullScreenController rather than the default.

Complete the following steps to use a custom JWFullScreenController:

  1. Override the playerViewControllerWillGoFullScreen method.

  2. Use your custom CustomJWFullScreenViewController to subclass JWFullScreenViewController.

    class CustomJWFullScreenViewController: JWFullScreenViewController {
    
    }
    

  1. Return an instance of your custom JWFullScreenController.
        func playerViewControllerWillGoFullScreen(_ controller: JWPlayerViewController) -> JWFullScreenViewController? {
                // Return instance of your subclassed full screen view controller
    return CustomJWFullScreenViewController()
        }