Picture-in-Picture Mode on Android Devices

10 min read A Guide to Using Picture-in-Picture Mode on Android Devices- written by Lilly Ihsan, Content Creator May 15, 2024 15:54 Picture-in-Picture Mode on Android Devices

1. Introduction to Picture-in-Picture Mode

The Picture-in-Picture (PiP) mode is a window that allows the video to be viewed along with other tasks on the device. This window can be moved around the screen, and this flexibility helps users to do different tasks like chatting, browsing, and sending emails while the video is being played. Android PiP mode was introduced in API 26 (Android 8.0 Oreo), and with Android Nougat or Marshmallow, the video displays on the screen. The PiP can be minimized to a smaller window which travels to one of the corners of the screen as the user proceeds with other tasks. It can be brought back to the main video window to view the video again. The life cycle of PiP is managed by the system and helps you to control the PiP window and customize it to create personalized PiP experiences. Android PiP mode is very similar to the Android multi-window mode, and the differences are as follows: PiP mode is a newer feature than the multi-window mode. In PiP mode, the window automatically enters into the PiP window mode. In multi-window, you have to manually specify both the window sizes.

Android's PiP mode helps in multitasking and allowing users to move from one application to the next with ease. As an Android app developer, integrating PiP into any developed application gives more control to multimedia-rich applications like media players, browsers, and also video calling applications. It allows the users to choose the best position and size of the PiP window for the best viewing experience. The following tutorial helps developers to understand and use PiP in their apps.

2. Enabling Picture-in-Picture Mode on Android

To use the picture-in-picture mode, you need to update the apps that you are going to use frequently. From there, you need to enable the feature in the settings section of your Android device. On an Android device, this function is available on any device. However, the availability varies from the version of your Android to the developer of the application. To check which version you have installed, you need to follow these steps. First, open the settings app and scroll down to the system section and click on the about phone option. Then check the Android version. The picture-in-picture mode is compatible with Android Nougat and Oreo versions. Platforms like YouTube and Facebook are the main applications that you can use to watch a video and enable the picture-in-picture mode.

The picture-in-picture mode was first introduced in the Android Oreo update. This feature is extremely useful because with it, you can use any of the apps installed on your device while using another at the same time. Picture-in-picture mode is a feature that is currently being used in the majority of streaming platforms. This feature will allow you to continue to watch a video while using another app.

3. Navigating and Interacting with Picture-in-Picture Windows

Closing the window: Once your task is done, or if you simply want to take a small break, the Picture-in-Picture window can be closed with a tap, or removed from the screen by sliding it to the side of your choosing. To close a window through a tap, open the Picture-in-Picture window's additional options and select the "Close" option at its bottom. This will close the window and let you return to your previous, full-screen app. If, instead, you want to remove the window by making it swipe away, simply drag the Picture-in-Picture window to your left or right and observe as it disappears from sight.

Resizing the window: If moving your window doesn't suit your interests, feel free to change its size. You can increase or decrease the window's size by pinching it with your thumb and index finger. This will change the size of the Picture-in-Picture window and give you the perfect multitasking experience.

Moving the window: You can move your Picture-in-Picture window anywhere on your screen with ease. To do so, simply tap and drag the window around using a single finger. Once you lift your finger, the window will stay right there. Drag the Picture-in-Picture window by its bottom to expand its size, and remember that the window will snap to the sides once you release it, letting you multitask easier.

4. Optimizing Apps for Picture-in-Picture Mode

When an app is in picture-in-picture mode, it is in a special state that is constrained in size. Because of these constraints, not all apps will work in picture-in-picture. For example, apps such as games and other full-screen experiences won't work in mean picture-in-picture mode. Apps can know when they are in the picture-in-picture mode because isInPictureInPictureMode() will be true.

If you choose to handle the picture-in-picture interactions yourself, you can call enterPictureInPictureMode() to enter picture-in-picture mode while your activity is in the resumed state. At any time after an activity has called enterPictureInPictureMode(), you can use the isPictureInPicture() method to check if the activity is currently in picture-in-picture mode.

Some devices that support picture-in-picture mode can enter the picture-in-picture mode for every app, not just those that have been optimized for it. If an app has been optimized, it enters picture-in-picture mode automatically when the user taps the home button. If an app has not been optimized, the system defers to the system's multitasking settings before allowing picture-in-picture mode to be active. For example, in multi-window mode, the app may be forced into picture-in-picture mode in a floating window within the multi-window mode.

5. Advanced Tips and Troubleshooting

When an app enters PiP mode, the app can update the state of the app and views; however, the app cannot request gesture input or update the window size. The app can request changes to views and other UI components. For example, the app can display a closed-caption track in the window when a video is playing. To specify that a given activity should not support picture-in-picture mode, include `android:supportsPictureInPicture="false"` in the AndroidManifest.xml file. If a user tries to navigate in an app while in PiP mode, the app should enforce the app's navigation rules to ensure that the app behaves consistently. The `getMaxNumPictureInPictureActions` callback is called when an app invokes `setActions`. When a caller calls `setActions` and passes a non-null array of actions, the `getMaxNumPictureInPictureActions` callback is called. If an app has picture-in-picture actions outside of the picture, surrogate data should have touch and focus blocking to prevent the actions in the PiP window from affecting the user's navigation around the app.

If you perform a function that exits the picture-in-picture window, such as making a call or casting a screen, the window will automatically close. An exception to this is if the foreground activity is part of a PiP-enabled app that has called `setAutopauseEnabled(false)` in the `PipParams` object. If there are multiple activities in the back stack of the same app and one of them is in PiP mode, and a new topmost activity is started, the system will enter paused state. At this time, the app needs to start the video or update the UI in the paused state of the picture-in-picture mode to avoid abnormally showing a frozen video.

User Comments (0)

Add Comment
We'll never share your email with anyone else.