Picture in Picture on Android TV (Android Development Patterns S3 Ep 2)

ever been watching a video on Android TV, but you still
wanted to browse around to look for something new? Then you need to use the
new Picture-in-Picture mode, available in Android N. Hi, everyone. I’m Wayne Piekarski from Google. And today, I’m going to talk
about Picture-in-Picture on Android TV and how to
quickly support it in your apps. Picture-in-Picture,
also known as PIP, is a new feature available
in Android N on Android TV devices. PIP builds on the new
Android and multi-window APIs to bring you an intuitive,
multi-window experience, specifically designed
for Android TV. With Picture-in-Picture
enabled in your app, users can continue
watching your content while they browse more
content in app and across apps on Android TV. The user selects the PIP icon to
put the video in the top right corner. PIP also helps your
users return to your app. So while they browse around
for different content, it’s now quick and easy for
them to return to your app, even if they’re in a
completely different app. Without PIP, once the user
leaves your app, they’re gone. If you press and
hold the Home button, it’ll bring up the
Recents list, which allows you to make the PIP
full-screen or to stop it. In order to support
PIP in your app, there are few simple changes
that you’ll need to make. The first to do
is you need to add these few lines to your payback
activity in your manifest file. This tells Android that your
activity is specifically designed to go into
PIP mode and can be resized by the system
when PIP is enabled. We suggest you only add
these tags to video playback activities, as they
provide the best user experience for PIP mode. And this is what users will
come to expect from the feature. Next, add a button to
your UI so that your users can activate PIP. If you’re using the
leanback support library, we’ve already added a new
Picture-in-Picture action class that allows
you to easily drop a PIP button into your
existing playback controls row. When the button
is clicked, simply run activity
enterPictureInPictureMode and Android will
handle the rest. At any time, you can
call the activity isInPictureInPictureMode method
to detect whether your activity is in PIP mode. For example, when you
switch to PIP mode, your activity is
considered to be paused. So you should continue
video playback and pause everything else. If you find that your video
pauses when you activate PIP, that’s likely because you’re
handling the play and pause logic in onResume and onPause. In Android N, we recommend
your play-pause logic happen in onStart, onStop instead. So be sure to move that
logic over to those methods if you encounter that issue. Finally, you may notice
that your Playback Controls row still shows up
in the PIP window. This may confuse users. So we’ll need to hide
those when we into PIP mode and show them again
once we exit PIP mode. If you implement the
media session properly, then play and pause controls
on the remote control or the Recents list will
still work on the PIP. Simply override the
onPictureInPictureModeChanged in your activity or fragment,
and hide your controls if you’re in PIP mode. And that’s it. You’re done. Your app now supports
PIP and is ready to use. Here’s a few extra
tips that will help make sure your
Picture-in-Picture experience is polished for your users. First, use the Android
launchMode=”singleTask” on your PIP enabled activity
to make sure you’re PIP window automatically closes when a user
starts playing a new video from within your application. We suggest you use the
Picture-in-Picture window only for displaying
your video content, as this provides the
best user experience. And finally, when you reach
the end of your video, you should either autoplay a
next video, or close the PIP. But don’t go back to the
full-screen user interface. So go and check out
our leanback sample, which shows you a full
implementation of how to incorporate
Picture-in-Picture in your app. Picture-in-Picture mode
provides your users with a great experience for
viewing and browsing content at the same time on Android TV. As you saw, enabling
PIP in your apps is easy and can help your users
stay engaged with your content beyond the confines of your app. So that’s it for today. Try out the PIP
support in the sample. And join us in our G+ community
to discuss this and other Andriod TV APIs. I’m Wayne Piekarski. And I’ll see you next time. [MUSIC PLAYING]

13 thoughts on “Picture in Picture on Android TV (Android Development Patterns S3 Ep 2)

  1. So it's your fault ("best user experience"..) that my TV can't handle PiP (like tuner+HDMI)? Well, thanks a bunch then. -.-
    In all honesty though, i'm freaking out over this issue – nothing i do seems to work because the device doesn't offer any more input sources.
    What am i to do?

  2. I see the removed patch (Remove picture in picture support.
    Change-Id: I7918f824205d27a470ba00a2ffac8e17e2152ffc).

  3. How to disable PiP or disable PiP in a specific app on Android TV / nVidia shield? There is a bug where I can't access content under the PiP icon, this worked before the PiP icon was added.. The app is called NRK and they are using the standard Android video player API. Please help!

  4. Wonder if it makes sense to keep this video online. It looks like PIP for TV is not running stabile and therefore taken away from the example

Leave a Reply

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