Created
August 3, 2019 10:41
-
-
Save momvart/b42db3675273e879227bb785f124ed67 to your computer and use it in GitHub Desktop.
A way of showing a PIP window on all apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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