How does picture in picture work




















An activity can enter PiP mode when the user taps the home button in button navigation mode or swipes up to home in gesture navigation mode. This is how Google Maps continues to display directions while the user runs another activity at the same time. Your app can move a video into PiP mode when the user navigates back from the video to browse other content. Your app can switch a video into PiP mode while a user watches the end of an episode of content.

The main screen displays promotional or summary information about the next episode in the series. Your app can provide a way for users to queue up additional content while they watch a video. The video continues playing in PiP mode while the main screen displays a content selection activity.

By default, the system does not automatically support PiP for apps. If you want support PiP in your app, register your video activity in your manifest by setting android:supportsPictureInPicture to true. Also, specify that your activity handles layout configuration changes so that your activity doesn't relaunch when layout changes occur during PiP mode transitions.

To enter picture-in-picture mode, an activity must call enterPictureInPictureMode. For example, the following code switches an activity to PiP mode when the user clicks a dedicated button in the app's UI:. You might want to include logic that switches an activty into PiP mode instead of going into the background. For example, Google Maps switches to PiP mode if the user presses the home or recents button while the app is navigating.

You can catch this case by overriding onUserLeaveHint :. Starting in Android 12, you can use the setAutoEnterEnabled flag to provide smoother transitions to PiP mode when swiping up to home in gesture navigation mode.

Builder , as follows:. The app should not wait for the onUserLeaveHint callback as it would have done in Android For example, an app may want to call setPictureInPictureParams on the very first playback and any following playback if the aspect ratio is changed.

Call setAutoEnterEnabled false as needed. When the activity enters or exits picture-in-picture mode, the system calls Activity. You should override these callbacks to redraw the activity's UI elements. Keep in mind that in PiP mode your activity is shown in a small window. Users cannot interact with your app's UI elements when it's in PiP mode and the details of small UI elements may be difficult to see. Video playback activities with minimal UI provide the best user experience.

If your app needs to provide custom actions for PiP, see Add controls in this document. Remove other UI elements before your activity enters PiP and restore them when your activity becomes fullscreen again:.

Starting in Android 12, the SourceRectHint flag is now reused to implement smoother animation when exiting out of PiP mode. If necessary, update the sourceRectHint before the system starts the exit transition. The app can attach a layout change listener to its root view or target view such as the video player view to detect the event and update the sourceRectHint before the animation begins.

The PiP window can display controls when the user opens the window's menu by tapping the window on a mobile device, or selecting the menu from the TV remote. If an app has an active media session , then play, pause, next, and previous controls will appear. Be careful. Android 12 adds the setSeamlessResizeEnabled flag, which provides a much smoother cross-fading animation when resizing non-video content in the PiP window.

Previously, resizing non-video content in a PiP window could create jarring visual artifacts. The setSeamlessResizeEnabled flag is set to true by default for backward-compatibility. Leave this set to true for video content, and change it to false for non-video content. When your activity switches to PiP, the system places the activity in the paused state and calls the activity's onPause method. Video playback should not be paused and should continue playing if the activity is paused while in PiP mode.

In Android 7. By doing this, you can avoid having to check if your app is in PiP mode in onPause and explicitly continuing playback. If you have to pause playback in your onPause implementation, check for PiP mode by calling isInPictureInPictureMode and handle playback appropriately, for example:.

When your activity switches out of PiP mode back to full-screen mode, the system resumes your activity and calls your onResume method. In your app, a user might select a new video when browsing for content on the main screen, while a video playback activity is in PiP mode.

Play the new video in the existing playback activity in full screen mode, instead of launching a new activity that might confuse the user. To ensure a single activity is used for video playback requests and switched into or out of PiP mode as needed, set the activity's android:launchMode to singleTask in your manifest:.

In your activity, override onNewIntent and handle the new video, stopping any existing video playback if needed. PiP might be disabled on devices that have low RAM.

PiP is intended for activities that play full-screen video. When switching your activity into PiP mode, avoid showing anything except video content. When an activity is in PiP mode, by default it doesn't get input focus. To receive input events while in PiP mode, use MediaSession. When your app is in PiP mode, video playback in the PiP window can cause audio interference with another app, such as a music player app or voice search app.

To avoid this, request audio focus when you start playing the video, and handle audio focus change notifications, as described in Managing Audio Focus. If you receive notification of audio focus loss when in PiP mode, pause or stop video playback. When your app is about to enter PiP, note only the top activity will enter Picture-in-Picture. In some situations such as on multi-window devices, it is possible the activity below will now be shown and become visible again alongside the PiP activity.

You should handle this case accordingly, including the activity below getting an onResume or an onPause callback. It is also possible that the user may interact with the activity.

For example, if you have a video list activity displayed and the playing video activity in PiP mode, the user might select a new video from the list and the PiP activity should update accordingly.

The option to keep the audio playing after docking the video sounds extremely useful for FaceTime calls, so you can temporarily make full use of your screen while talking to the other person. For example, maybe you need to carefully follow walking directions, but you still want them to be able to see your face on video. Pinch to zoom is the other potential standout with Apple's Picture in Picture tool. It doesn't exist for Android. On phones like the Samsung Galaxy S20 and OnePlus 8 Pro , I could zoom to make it a little larger, and a second zoom attempt opened it to full size.

Apple's method gives you true scaling, and hopefully other phone brands will pay attention. Apple's new feature is advertised to work with video only, compared with PiP on Android, which also works with Google Maps. For people with a lamentable sense of direction, keeping one eye on walking directions while doing something else could be a huge convenience. Hopefully Apple will expand in the future to include Apple -- and Google -- maps within the Picture in Picture realm.

Now that you've mastered Picture in Picture, check out the rest of our iOS 14 tips and tricks. Including new privacy features , and a sweet new selfie trick you'll love. Be respectful, keep it civil and stay on topic.

We delete comments that violate our policy , which we encourage you to read. Discussion threads can be closed at any time at our discretion. Why iOS 14's Picture in Picture feature will transform your iPhone experience The iPhone now has one of Android's beloved features, and we'll show you how to use it. Jason Cipriani. To control which apps make use of PiP, open Settings and pick Apps and notifications , Advanced , Special app access , and Picture-in-picture.

Picture-in-picture is similar on iOS and iPadOS, but you can pinch and drag with two fingers to change the size of the PiP video thumbnail.

Tap, hold, and drag on the video window to move it to a new position on screen, and tap briefly on the window to bring up the play and pause controls. Should you want to turn this picture-in-picture behavior off on an iPhone or iPad, you can do so from Settings: Tap General , then Picture in Picture , and turn the toggle switch off.

When the switch is off, leaving an app where something is playing will simply stop playback and quit the app. Click and drag the edges of windows to resize them, and click and drag the top of a window to move it around on screen.

You can click and drag the edges of the window to resize it, and click and drag on the main part of the video overlay to move it to a different corner of the screen. By choosing I Accept , you consent to our use of cookies and other tracking technologies. Cybersecurity Mobile Policy Privacy Scooters. Phones Laptops Headphones Cameras. Tablets Smartwatches Speakers Drones. Accessories Buying Guides How-tos Deals. Health Energy Environment. YouTube Instagram Adobe. Kickstarter Tumblr Art Club.



0コメント

  • 1000 / 1000