-
-
Save CSaratakij/f75da30595ad20b4fb6648c457a62a53 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