1*d353a188SXin LiAndroid PictureInPicture Sample (Kotlin) 2*d353a188SXin Li=================================== 3*d353a188SXin Li 4*d353a188SXin LiThis sample demonstrates basic usage of Picture-in-Picture mode for handheld devices. 5*d353a188SXin LiThe sample plays a video. The video keeps on playing when the app is turned in to 6*d353a188SXin LiPicture-in-Picture mode. On Picture-in-Picture screen, the app shows an action item to 7*d353a188SXin Lipause or resume the video. 8*d353a188SXin Li 9*d353a188SXin LiIntroduction 10*d353a188SXin Li------------ 11*d353a188SXin Li 12*d353a188SXin LiAs of Android O, activities can launch in [Picture-in-Picture (PiP)][1] mode. PiP is a 13*d353a188SXin Lispecial type of [multi-window][2] mode mostly used for video playback. 14*d353a188SXin Li 15*d353a188SXin LiThe app is *paused* when it enters PiP mode, but it should continue showing content. For this 16*d353a188SXin Lireason, you should make sure your app does not pause playback in its [onPause()][3] 17*d353a188SXin Lihandler. Instead, you should pause video in [onStop()][4]. For more information, see [Multi-Window 18*d353a188SXin LiLifecycle][5]. 19*d353a188SXin Li 20*d353a188SXin LiTo specify that your activity can use PIP mode, set `android:supportsPictureInPicture` to `true` in 21*d353a188SXin Lithe manifest. (Beginning with the O Developer Preview, you do not need to set 22*d353a188SXin Li`android:resizeableActivity` to `true` if you are supporting PIP mode, either on Android TV or on 23*d353a188SXin Liother Android devices; you only need to set `android:resizeableActivity` if your activity supports 24*d353a188SXin Liother multi-window modes.) 25*d353a188SXin Li 26*d353a188SXin LiYou can pass a [PictureInPictureParams][6] to [enterPictureInPictureMode()][7] to specify how an 27*d353a188SXin Liactivity should behave when it is in PiP mode. You can also use it to call 28*d353a188SXin Li[setPictureInPictureParams()][8] and update the current behavior. If the app is in not PiP mode, it 29*d353a188SXin Liwill be used for later call of [enterPictureInPictureMode()][7]. 30*d353a188SXin Li 31*d353a188SXin LiWith a [PictureInPictureParams][6], you can specify aspect ratio of PiP activity and action items 32*d353a188SXin Liavailable for PiP mode. The aspect ratio is used when the activity is in PiP mode. The action items 33*d353a188SXin Liare used as menu items in PiP mode. You can use a [PendingIntent][9] to specify what to do when the 34*d353a188SXin Liitem is selected. 35*d353a188SXin Li 36*d353a188SXin Li[1]: https://developer.android.com/guide/topics/ui/multi-window.html 37*d353a188SXin Li[2]: https://developer.android.com/guide/topics/ui/picture-in-picture.html 38*d353a188SXin Li[3]: https://developer.android.com/reference/android/app/Activity.html#onPause() 39*d353a188SXin Li[4]: https://developer.android.com/reference/android/app/Activity.html#onStop() 40*d353a188SXin Li[5]: https://developer.android.com/guide/topics/ui/multi-window.html#lifecycle 41*d353a188SXin Li[6]: https://developer.android.com/reference/android/app/PictureInPictureParams.html 42*d353a188SXin Li[7]: https://developer.android.com/reference/android/app/Activity.html#enterPictureInPictureMode(android.app.PictureInPictureParams) 43*d353a188SXin Li[8]: https://developer.android.com/reference/android/app/Activity.html#setPictureInPictureParams(android.app.PictureInPictureParams) 44*d353a188SXin Li[9]: https://developer.android.com/reference/android/app/PendingIntent.html 45*d353a188SXin Li 46*d353a188SXin LiPre-requisites 47*d353a188SXin Li-------------- 48*d353a188SXin Li 49*d353a188SXin Li- Android SDK 26 50*d353a188SXin Li- Android Build Tools v26.0.2 51*d353a188SXin Li- Android Support Repository 52*d353a188SXin Li 53*d353a188SXin LiScreenshots 54*d353a188SXin Li------------- 55*d353a188SXin Li 56*d353a188SXin Li<img src="screenshots/1-main.png" height="400" alt="Screenshot"/> <img src="screenshots/2-pip.png" height="400" alt="Screenshot"/> 57*d353a188SXin Li 58*d353a188SXin LiGetting Started 59*d353a188SXin Li--------------- 60*d353a188SXin Li 61*d353a188SXin LiThis sample uses the Gradle build system. To build this project, use the 62*d353a188SXin Li"gradlew build" command or use "Import Project" in Android Studio. 63*d353a188SXin Li 64*d353a188SXin LiSupport 65*d353a188SXin Li------- 66*d353a188SXin Li 67*d353a188SXin Li- Google+ Community: https://plus.google.com/communities/105153134372062985968 68*d353a188SXin Li- Stack Overflow: http://stackoverflow.com/questions/tagged/android 69*d353a188SXin Li 70*d353a188SXin LiIf you've found an error in this sample, please file an issue: 71*d353a188SXin Lihttps://github.com/googlesamples/android-PictureInPicture 72*d353a188SXin Li 73*d353a188SXin LiPatches are encouraged, and may be submitted by forking this project and 74*d353a188SXin Lisubmitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. 75*d353a188SXin Li 76*d353a188SXin LiLicense 77*d353a188SXin Li------- 78*d353a188SXin Li 79*d353a188SXin LiCopyright 2017 The Android Open Source Project, Inc. 80*d353a188SXin Li 81*d353a188SXin LiLicensed to the Apache Software Foundation (ASF) under one or more contributor 82*d353a188SXin Lilicense agreements. See the NOTICE file distributed with this work for 83*d353a188SXin Liadditional information regarding copyright ownership. The ASF licenses this 84*d353a188SXin Lifile to you under the Apache License, Version 2.0 (the "License"); you may not 85*d353a188SXin Liuse this file except in compliance with the License. You may obtain a copy of 86*d353a188SXin Lithe License at 87*d353a188SXin Li 88*d353a188SXin Lihttp://www.apache.org/licenses/LICENSE-2.0 89*d353a188SXin Li 90*d353a188SXin LiUnless required by applicable law or agreed to in writing, software 91*d353a188SXin Lidistributed under the License is distributed on an "AS IS" BASIS, WITHOUT 92*d353a188SXin LiWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 93*d353a188SXin LiLicense for the specific language governing permissions and limitations under 94*d353a188SXin Lithe License. 95