# Drop-in Android Video -- Exoplayer2 with Picture in Picture

DevFeed: [Drop-in Android Video -- Exoplayer2 with Picture in Picture](<https://devfeed.tech/articles/drop-in-android-video-exoplayer2-with-picture-in-picture-26010.md>)

Original publisher: [Read original article](<https://medium.com/s23nyc-tech/drop-in-android-video-exoplayer2-with-picture-in-picture-e2d4f8c1eb30?source=rss-2ffcf6104135------2>)

Author: Stacy Devino

Published: 2018-09-13T15:58:58Z

Content type: tutorial

Language: en

Sources: [Stacy Devino](<https://devfeed.tech/sources/stories-by-stacy-devino-on-medium.md>)

Topics: [ExoPlayer](<https://devfeed.tech/topics/exoplayer.md>), [Android](<https://devfeed.tech/topics/android.md>), [picture-in-picture](<https://devfeed.tech/topics/picture-in-picture.md>), [User Interfaces](<https://devfeed.tech/topics/user-interfaces.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [exoplayer2](<https://devfeed.tech/tags/exoplayer2.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [nike](<https://devfeed.tech/tags/nike.md>), [picture-in-picture](<https://devfeed.tech/tags/picture-in-picture.md>), [video](<https://devfeed.tech/tags/video.md>)

## AI overview

The excerpt shows how to build an in-app Android player with ExoPlayer2: use SimpleExoPlayer with PlayerView, add the core, HLS, UI, and MediaSession extension libraries, select HLS or extractor media sources by URL type, and release the player in onStop(). For Picture-in-Picture (PiP), check Android version and device feature support, hide player controls, and enter PiP from onUserLeaveHint() and optionally onBackPressed(). The article reports that the Android Studio API available to its author could not check the user's PiP permission directly; it suggests checking whether the activity entered PiP after a short delay and falling back to back navigation if it did not. It also recommends finishAndRemoveTask() when the PiP activity stops, and a MediaSessionConnector for PiP playback controls. The excerpt warns that PiP can outlive the main app and proposes an onTaskRemoved() service signal to close the player activity. These are the article's version-specific workarounds; the excerpt does not establish their behavior on current Android versions.

## Source excerpt

Beautiful, interactive video content done easy. Video has been shown to increase engagement in apps and with content. How else could gif servicing apps be worth tens of millions and Youtube influencers be selling billions of dollars of product? The problem is that video in Android can be difficult. You are given the assumption that the video types you will support are pretty basic : embedded MPEG video, URLs to MP4/AVI files, and HLS Streaming. A naive approach would be to use the embedded video player sent with Intents, but that takes the user out of your app. You think, 🤔 " I'll just use the Android VideoView class with AppCompat ." Then you realize that it is nearly impossible to make the experience consistent across users because of codec support and whatever the phone manufacturer may have customized in the video player. Finally you settle on Exoplayer2 because it is the package everyone, including Google, uses. Upon further inspection, you quickly realize that it requires a lot of code to make it work and the example application on the Github is confusing, far too extensive for what you are doing. Another route you could take is ExoMedia by Brian Wernick, but it trades extensibility, theming, and control for simplicity. Fortunately, you only need the Exoplayer2 libraries to have a fantastic video player experience within your app. SimpleExoplayer "2" the Rescue First you need to make an app which can receive a URL and play it using Exoplayer. For this, you will need SimpleExoplayer and the Playerview from the UI package. Playerview has easy to manipulate styling/theming elements as well as available media controls. SimpleExoPlayer gives you a preconfigured player to work with without having to handle deeper logic yourself. Start by adding the Gradle dependencies to your build.gradle : implementation 'com.google.android.exoplayer:exoplayer-core:2.X.X' implementation 'com.google.android.exoplayer:exoplayer-hls:2.X.X' implementation 'com.google.android.exoplayer: