Skip to content

Instantly share code, notes, and snippets.

@momvart
Created August 3, 2019 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save momvart/b42db3675273e879227bb785f124ed67 to your computer and use it in GitHub Desktop.
Save momvart/b42db3675273e879227bb785f124ed67 to your computer and use it in GitHub Desktop.
A way of showing a PIP window on all apps
val windowManager = this.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val windowLayoutParams = WindowManager.LayoutParams()
windowLayoutParams.width = 300
windowLayoutParams.height = 300
windowLayoutParams.x = 400
windowLayoutParams.y = 400
windowLayoutParams.format = PixelFormat.TRANSLUCENT
windowLayoutParams.gravity = Gravity.TOP or Gravity.LEFT
if (Build.VERSION.SDK_INT >= 26)
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
else
windowLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
val texture = TextureView(this) //A simple TextureView to show video in
val frame = FrameLayout(this).apply {
addView(texture, -1, -1)
}
windowManager.addView(frame, windowLayoutParams) //Displaying the window
player.setVideoTextureView(texture) //Connect it to exoplayer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment