Adding Picture in Picture to your App

Adding Picture in Picture to your App


SEAN MCQUILLAN: With
picture-in-picture, you can overlay other apps
where your user is doing critical tasks, such as
watching a video or navigating. It’s available whenever your
app is running on Oreo or above. Let’s dive in on how
to add it to your app. A picture-in-picture
overlay is a mode that you enter from
a visible activity. The user will see the
contents of the activity during the entire
transition animation, so you’ll want to
optimize this experience. Of course, it does count
as a configuration change. To avoid visual hiccups, make
sure you handle configuration changes in your activity. How do you design for PIP? Well, designing for
Picture-In-Picture, or PIP, is simple. It’s a small window,
so you simply hide all of the views that
aren’t relevant to the overlay. For example, if you’re
playing a video, you should only show
the video content and hide all of the other views
to create a simple overlay. Another important thing to
note when designing for PIP– overlays have a fixed aspect
ratio you configure in code. This lets you specify
the perfect aspect ratio for your content. Now, to support user interaction
with your PIP overlay, you may supply a small number of
controls called remote actions. You can use remote actions
for simple interaction, such as playing or
pausing a video. When in PIP mode, your activity
won’t get any touch events. Instead, you configure remote
actions with PendingIntents. When a user presses
a remote action, the PendingIntent will
be fired, and you’ll be notified via a
BroadcastReceiver or other means. When your user expands
the overlay back to a regular activity, you’ll
get notified via a callback. You’ll need to reshow
all of your hidden views when your activity
exits PIP mode. And there’s one
more detail to note. When an activity
enters PIP mode, it starts a new task
without a back stack. When it exits PIP
mode, it does not bring back the original task. So by default, Back
will leave your app. Your user’s navigation
history is lost. To recover your back stack,
check out our blog post on recovering navigation state. Picture-in-picture
is a great way to continue your users’ critical
tasks as they use their phone. I’ve just covered
the essentials here. To learn more, check
out the blog post and documentation on
picture-in-picture linked in the description. Thanks for watching. See you next time. [MUSIC PLAYING]

Only registered users can comment.

  1. Pocket casts and Google Maps (while getting directions) have Picture in Picture and it's awesome!
    But Youtube doesn't and probably never will have it…..

  2. Is it bad that i'm still using java for app development?
    i'm still in College, so i don't have enough time to practice Kotlin since it's my final term before graduation!!!

  3. what if u want to ask the user to enable pip mode? is there any way to do that? To open the pip mode settings screen directly? Because i couldn't find any constant on Settings class to do that :p Or am I mistaken? 😛

  4. Okay, I'm just a person who wants to have picture in picture to view dailymotion videos when I'm doing something else too. Is that possible to do as an end user who knows almost nothing?

Leave a Reply

Your email address will not be published. Required fields are marked *