Picture-in-Picture: Working in Android Oreo




From release of the Android O, which saw some exciting new additions for us to get our hands on!
One of the most noticeable user-facing changes is the introduction of a picture in picture (PIP) option – similar to an Apple iPad feature added in iOS 9 – which should make multitasking easier in some circumstances.  PIP is a special type of multi-window mode mostly used for video playback. PIP mode is already available for Android TV; Android O makes the feature available on other Android devices.
Let’s take a look at this exciting new feature and how we can implement it into our Android applications!
To learn more about Picture-in-Picture I created a playground project to have a play with the new features. You can check this out for yourself here!

What is Picture-In-Picture?

Picture-in-Picture (PiP) allows you to keep videos open as they play on top of of another screen. This wouldn’t be the same as the multi-window feature which allows users to keep two apps open simultaneously, but instead is likely to be more similar to the way YouTube videos play in a small player at the bottom right corner of the screen after you minimize them which allows you to continue scrolling through YouTube and looking at other videos. The change here would be that users will have the ability to do the same type of thing but while in other apps as well.

Implementing Picture-in-Picture

Implementing Picture-in-Picture into our applications is a simple process. There’s only several steps allow us to display PiP-windows to our users!

picture-in-picture support

The first step, is allow your activity to support PiP. Set android:supportsPictureInPicture tag to true:

Enter Picture In Picture Mode

To enter picture-in-picture mode, an activity must call enterPictureInPictureMode(). The other thing to keep in mind is that you need specials parameters to enter to PiP mode from your activity:
You need to set an aspect ratio to PiP parameters builder. The aspect ratio is used when the activity is in PiP mode. To do that, you have to pass the width and height of your video view. Then, you can call to enterPictureInPictureMode passing the PiP parameters built.

Handling UI during picture-in-picture

When the activity enters or exits picture-in-picture mode the system calls Activity.onPictureInPictureModeChanged() or Fragment.onPictureInPictureModeChanged().

References

Comments

Popular posts from this blog

Android Debug Database: A Library for Debugging Android Databases and Shared Preferences

How to Use Kotlin in Your Android Projects

Reactive Programming with RxBinding

Introduction to Spring Animation

Getting started with Android Fingerprint Authentication

Exploring Android O: Autosizing TextViews

Exploring Android O: Fonts in XML

Kotlin: Do more with less code

Introduction to Android Bottom Navigation View