Enter and exit full screen (iOS v4)

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, full screen can be entered and exited in several ways. The following table lists each approach.

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 JWPlayerViewController

📘

If you are only using JWPlayerView, you must implement full screen capability yourself or 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 JWPlayerViewController 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.



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 dismissFullScreen(animated: Bool, completion: (() -> Void)? = nil)
- (void)dismissFullScreenAnimated:(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

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 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 into full screen
completion ClosureClosure called after the player has transitioned to 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) {

    }


playerViewControllerDidDismissFullScreen()

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


func playerViewControllerDidDismissFullScreen(_ controller: JWPlayerViewController) {}
ArgumentDescription
controller JWPlayerViewerControllerJWPlayerViewController emitting the event

playerViewControllerDidGoFullScreen()

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


func playerViewControllerDidGoFullScreen(_ controller: JWPlayerViewController) {}
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) {}
ArgumentDescription
controller JWPlayerViewerControllerJWPlayerViewController emitting the event

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
    }
ArgumentDescription
controller JWPlayerViewerControllerJWPlayerViewController emitting the event


Customize the JWFullScreenController

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