Skip to content

Latest commit

 

History

History

picture-in-picture

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Android PictureInPicture Sample

This sample demonstrates basic usage of Picture-in-Picture mode for handheld devices. The sample plays a video. The video keeps on playing when the app is turned in to Picture-in-Picture mode. On Picture-in-Picture screen, the app shows an action item to pause or resume the video.

Introduction

As of Android 8.0 Oreo (API level 26), activities can launch in Picture-in-Picture (PiP) mode. PiP is a special type of multi-window mode mostly used for video playback.

The app is paused when it enters PiP mode, but it should continue showing content. For this reason, you should make sure your app does not pause playback in its onPause() handler. Instead, you should pause video in onStop(). For more information, see Multi-Window Lifecycle.

To specify that your activity can use PIP mode, set android:supportsPictureInPicture to true in the manifest. (You do not need to set android:resizeableActivity to true if you are only supporting PIP mode, either on Android TV or on other Android devices; you only need to set android:resizeableActivity if your activity supports other multi-window modes.)

You can pass a PictureInPictureParams to enterPictureInPictureMode() to specify how an activity should behave when it is in PiP mode. You can also use it to call setPictureInPictureParams() and update the current behavior.

With a PictureInPictureParams, you can specify aspect ratio of PiP activity and action items available for PiP mode. The aspect ratio is used when the activity is in PiP mode. The action items are used as menu items in PiP mode. You can use a PendingIntent to specify what to do when the item is selected.