Class PictureInPictureManager

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


        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
                                     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.
        activity - the Activity
        videoView - the BaseVideoView
      • unregisterActivity

        public void unregisterActivity​( activity)
        Unregister the previously registered activity and clean its references.
        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.
        true if it is in Picture-in-Picture mode.
        See Also:
      • 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.
        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.
        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.
        aspectRatio - the new aspect ratio for the activity in picture-in-picture, must be between 2.39:1 and 1:2.39 (inclusive).
        the PictureInPictureManager instance.
      • setUserActions

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

        public PictureInPictureManager setSourceRectHint​(@Nullable
        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.
        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)
        the PictureInPictureManager instance.
      • setClosedCaptionsEnabled

        public PictureInPictureManager setClosedCaptionsEnabled​(boolean closedCaptionsEnabled)
        Enables or disables closed captions for Picture in Picture mode.
        closedCaptionsEnabled - true to enable closed captions.
        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.
        onUserLeaveEnabled - true to enable.
        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.
        scaleFactor - the scale factor
        the PictureInPictureManager instance.