Last active
February 2, 2024 00:13
-
-
Save Oleur/acefc1c5502449fc9df6ad9b39644e24 to your computer and use it in GitHub Desktop.
Get current Android activity and init an Android object from Unity
This file contains hidden or 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
AndroidJavaObject localMediaPlayer = null; | |
using (AndroidJavaClass javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) | |
{ | |
using (currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) | |
{ | |
localMediaPlayer = new AndroidJavaObject("my/plugin/vr/ExoPlayerBridge", currentActivity); | |
if (localMediaPlayer != null) | |
{ | |
// Do some work with your java object outside the Android UI thread | |
localMediaPlayer.Call("addSubtitles", subtitleURL); | |
currentActivity.Call("runOnUiThread", new AndroidJavaRunnable(() => | |
{ | |
// Do some work on Android UI thread | |
localMediaPlayer.Call("prepare", true); | |
})); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment