1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Copyright 2017 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16--> 17<sample> 18 <name>PictureInPicture</name> 19 <group>Media</group> 20 <package>com.example.android.pictureinpicture</package> 21 <minSdk>26</minSdk> 22 23 <strings> 24 <intro> 25 This sample demonstrates basic usage of Picture-in-Picture mode for handheld devices. 26 The sample plays a video. The video keeps on playing when the app is turned in to 27 Picture-in-Picture mode. On Picture-in-Picture screen, the app shows an action item to 28 pause or resume the video. 29 </intro> 30 </strings> 31 32 <template src="base-build"/> 33 34 <metadata> 35 <status>PUBLISHED</status> 36 <categories>Media, Android Oreo</categories> 37 <technologies>Android</technologies> 38 <languages>Java</languages> 39 <solutions>Mobile</solutions> 40 <level>ADVANCED</level> 41 <icon>screenshots/icon-web.png</icon> 42 <screenshots> 43 <img>screenshots/1-main.png</img> 44 <img>screenshots/2-pip.png</img> 45 </screenshots> 46 <api_refs> 47 <android>android.app.PictureInPictureParams</android> 48 <android>android.app.RemoteAction</android> 49 <android>android.app.PendingIntent</android> 50 <android>android.support.v4.media.session.MediaSessionCompat</android> 51 </api_refs> 52 53 <description> 54 <![CDATA[ 55This sample demonstrates basic usage of Picture-in-Picture mode for handheld devices. 56The sample plays a video. The video keeps on playing when the app is turned in to 57Picture-in-Picture mode. On Picture-in-Picture screen, the app shows an action item to 58pause or resume the video. 59]]> 60 </description> 61 62 <intro> 63 <![CDATA[ 64As of Android O, activities can launch in [Picture-in-Picture (PiP)][1] mode. PiP is a 65special type of [multi-window][2] mode mostly used for video playback. 66 67The app is *paused* when it enters PiP mode, but it should continue showing content. For this 68reason, you should make sure your app does not pause playback in its [onPause()][3] 69handler. Instead, you should pause video in [onStop()][4]. For more information, see [Multi-Window 70Lifecycle][5]. 71 72To specify that your activity can use PIP mode, set `android:supportsPictureInPicture` to `true` in 73the manifest. (Beginning with Android O, you do not need to set 74`android:resizeableActivity` to `true` if you are supporting PIP mode you only need to 75`setrandroid:resizeableActivity` if your activity supports other multi-window modes.) 76 77You can pass a [PictureInPictureParams][6] to [enterPictureInPictureMode()][7] to specify how an 78activity should behave when it is in PiP mode. You can also use it to call 79[setPictureInPictureParams()][8] and update the current behavior. If the app is in not PiP mode, it 80will be used for later call of [enterPictureInPictureMode()][7]. 81 82With a [PictureInPictureParams][6], you can specify aspect ratio of PiP activity and action items 83available for PiP mode. The aspect ratio is used when the activity is in PiP mode. The action items 84are used as menu items in PiP mode. You can use a [PendingIntent][9] to specify what to do when the 85item is selected. 86 87[1]: https://developer.android.com/guide/topics/ui/picture-in-picture.html 88[2]: https://developer.android.com/guide/topics/ui/multi-window.html 89[3]: https://developer.android.com/reference/android/app/Activity.html#onPause() 90[4]: https://developer.android.com/reference/android/app/Activity.html#onStop() 91[5]: https://developer.android.com/guide/topics/ui/multi-window.html#lifecycle 92[6]: https://developer.android.com/reference/android/app/PictureInPictureParams.html 93[7]: https://developer.android.com/reference/android/app/Activity.html#enterPictureInPictureMode(android.app.PictureInPictureParams) 94[8]: https://developer.android.com/reference/android/app/Activity.html#setPictureInPictureParams(android.app.PictureInPictureParams) 95[9]: https://developer.android.com/reference/android/app/PendingIntent.html 96]]> 97 </intro> 98 </metadata> 99 100</sample> 101