Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android textureview player #1

Merged
merged 15 commits into from
Aug 6, 2021
Merged

Conversation

ivanarellano
Copy link

This branch will allow all supported android devices to render an unobstructed unity flutter widget view. This is done by calling UnityPlayer::addViewToPlayer() to swap the built in SurfaceView with a TextureView. Only android devices older than SDK version 26 (Oreo) will have this change made at runtime.

The code in this branch is based on comments from this ticket: juicycleff#190

@@ -43,6 +46,27 @@ class UnityPlayerUtils {
if (!reInitialize) {
activity.window.setFormat(PixelFormat.RGBA_8888)
unityPlayer = UnityPlayer(activity, ule)

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand any of this lol. Which is fine. Just one question out of curiosity. This if seems to be checking if the version number is below zero? Wondering what this is checking.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build.VERSION_CODES.O at first glance does look like a 0. I wish they didn't truncate "Oreo" to "O". At runtime this constant int is 26. https://developer.android.com/reference/android/os/Build.VERSION_CODES#O

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding what the code does, the majority of the work is happening within the unity generated library via unityPlayer!!.addViewToPlayer(view, true). The code above that is instantiating a TextureView from the Android SDK and setting it up so that the unity player view renders to it. The unity player shows our newly made TextureView because calling addViewToPlayer swaps the internal surface with our TextureView.

@jakeobrien jakeobrien merged commit 8099f45 into master Aug 6, 2021
@jakeobrien jakeobrien deleted the android-textureview-player branch August 6, 2021 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants