Class PictureInPicture

java.lang.Object
com.codename1.media.PictureInPicture

public final class PictureInPicture extends Object

Picture in picture: shrinks the app into a floating window while video keeps playing, so the user can work in another app.

Supported on Android 8 and later, where the whole app window becomes the floating window. Hide controls and other chrome while #isActive() is true, leaving only the video. Referencing this class makes the Android build declare supportsPictureInPicture on the main activity. iOS and the simulator report #isSupported() as false.

if (PictureInPicture.isSupported()) {
    PictureInPicture.addListener(new SuccessCallback<Boolean>() {
        public void onSucess(Boolean active) {
            Log.p("Picture in picture: " + active);
        }
    });
    PictureInPicture.enter(16, 9);
}
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Adds a listener told, on the EDT, when the app enters or leaves picture in picture.
    static boolean
    enter(int aspectWidth, int aspectHeight)
    Asks the system to enter picture in picture with the given aspect ratio, for example 16 by 9.
    static boolean
    True while the app is shown as a picture in picture window.
    static boolean
    True when the app can enter picture in picture.
    static void
    Removes a listener added with #addListener(SuccessCallback).
    static void
    setImplementation(com.codename1.impl.CodenameOneImplementation impl)
    Invoked internally from Display, this method is for internal use only

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • setImplementation

      public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl)

      Invoked internally from Display, this method is for internal use only

      Parameters
      • impl: implementation instance
    • isSupported

      public static boolean isSupported()

      True when the app can enter picture in picture.

      Returns

      true when supported

    • enter

      public static boolean enter(int aspectWidth, int aspectHeight)

      Asks the system to enter picture in picture with the given aspect ratio, for example 16 by 9.

      Parameters
      • aspectWidth: the width part of the aspect ratio

      • aspectHeight: the height part of the aspect ratio

      Returns

      true when the request was accepted

    • isActive

      public static boolean isActive()

      True while the app is shown as a picture in picture window.

      Returns

      true while active

    • addListener

      public static void addListener(SuccessCallback<Boolean> listener)

      Adds a listener told, on the EDT, when the app enters or leaves picture in picture.

      Parameters
      • listener: receives true on entering and false on leaving
    • removeListener

      public static void removeListener(SuccessCallback<Boolean> listener)

      Removes a listener added with #addListener(SuccessCallback).

      Parameters
      • listener: the listener to remove