Class PictureInPictureManager


  • public class PictureInPictureManager
    extends java.lang.Object
    The class responsible to manage the Picture-in-Picture mode.
    • Field Detail

      • DEFAULT_CLOSED_CAPTION_REDUCTION_SCALE_FACTOR

        public static final float DEFAULT_CLOSED_CAPTION_REDUCTION_SCALE_FACTOR
        The default value is to reduce Closed Captions by 50% when in Picture-in-Picture mode.
        See Also:
        Constant Field Values
    • Method Detail

      • registerActivity

        public void registerActivity​(@NonNull
                                     android.app.Activity activity,
                                     @NonNull
                                     BaseVideoView videoView)
        This method registers and holds a weak reference to the Activity that will be put into Picture-in-Picture mode. You can have only one registered Activity at a time. This method is only supported for Android versions equal or greater than Build.VERSION_CODES.O, otherwise the method will not do anything.
        Parameters:
        activity - the Activity
        videoView - the BaseVideoView
      • unregisterActivity

        public void unregisterActivity​(android.app.Activity activity)
        Unregister the previously registered activity and clean its references.
        Parameters:
        activity - the activity to unregister.
      • isInPictureInPictureMode

        public boolean isInPictureInPictureMode()
        Checks if there is a registered activity and calls that activity method Activity.isInPictureInPictureMode(). This only applies for Android Oreo or higher, otherwise it will always return false.
        Returns:
        true if it is in Picture-in-Picture mode.
        See Also:
        Activity.isInPictureInPictureMode()
      • isPictureInPictureEnabled

        public boolean isPictureInPictureEnabled()
        PictureInPictureManager will be disabled if there is no Activity registered or if the Activity previously registered was destroyed. This only applies for Android Oreo or higher, otherwise it will always return false. PictureInPictureManager will be temporarily disabled if the current video is a 360 video, which is currently not supported in Picture-in-Picture mode.
        Returns:
        true if enabled.
      • onUserLeaveHint

        public void onUserLeaveHint()
        This method calls enterPictureInPictureMode() if the PictureInPictureManager is configured to do so. You can enable this behavior by calling setOnUserLeaveEnabled(boolean) to true. By Default this behavior is disabled. This method must be called from the Activity.onUserLeaveHint() method.
      • onPictureInPictureModeChanged

        public void onPictureInPictureModeChanged​(boolean isInPictureInPictureMode,
                                                  android.content.res.Configuration newConfig)
        This method reacts to the Picture-in-Picture changes and emits EventType.DID_ENTER_PICTURE_IN_PICTURE_MODE and EventType.DID_EXIT_PICTURE_IN_PICTURE_MODE events. This method must be called from the Activity.onPictureInPictureModeChanged(boolean, Configuration) ()} method.
        Parameters:
        isInPictureInPictureMode - true if it is in Picture-inPicture mode.
        newConfig - the new configuration.
      • setAspectRatio

        public PictureInPictureManager setAspectRatio​(@Nullable
                                                      android.util.Rational aspectRatio)
        Sets the aspect ratio. This aspect ratio is defined as the desired width / height, and does not change upon device rotation.
        Parameters:
        aspectRatio - the new aspect ratio for the activity in picture-in-picture, must be between 2.39:1 and 1:2.39 (inclusive).
        Returns:
        the PictureInPictureManager instance.
      • setUserActions

        public PictureInPictureManager setUserActions​(@Nullable
                                                      java.util.List<android.app.RemoteAction> userActions)
        Sets the user actions. If there are more than Activity.getMaxNumPictureInPictureActions() actions, then the input list will be truncated to that number.
        Parameters:
        userActions - the new actions to show in the picture-in-picture menu.
        Returns:
        the PictureInPictureManager instance.
        See Also:
        RemoteAction
      • setSourceRectHint

        public PictureInPictureManager setSourceRectHint​(@Nullable
                                                         android.graphics.Rect sourceRectHint)
        Sets the source bounds hint. These bounds are only used when an activity first enters picture-in-picture, and describe the bounds in window coordinates of activity entering picture-in-picture that will be visible following the transition. For the best effect, these bounds should also match the aspect ratio in the arguments.
        Parameters:
        sourceRectHint - window-coordinate bounds indicating the area of the activity that will still be visible following the transition into picture-in-picture (eg. the video view bounds in a video player)
        Returns:
        the PictureInPictureManager instance.
      • setClosedCaptionsEnabled

        public PictureInPictureManager setClosedCaptionsEnabled​(boolean closedCaptionsEnabled)
        Enables or disables closed captions for Picture in Picture mode.
        Parameters:
        closedCaptionsEnabled - true to enable closed captions.
        Returns:
        the PictureInPictureManager instance.
      • setOnUserLeaveEnabled

        public PictureInPictureManager setOnUserLeaveEnabled​(boolean onUserLeaveEnabled)
        Enables or disables entering into Picture in Picture mode when the user has put the activity in the background, for example, when of pressing the Home key.
        Parameters:
        onUserLeaveEnabled - true to enable.
        Returns:
        the PictureInPictureManager instance.
      • setClosedCaptionsReductionScaleFactor

        public PictureInPictureManager setClosedCaptionsReductionScaleFactor​(float scaleFactor)
        Sets reduction the scale factor for closed captions when entering Picture in Picture mode. The values accepted must be between 0 and 1.
        Parameters:
        scaleFactor - the scale factor
        Returns:
        the PictureInPictureManager instance.