Skip to content

Instantly share code, notes, and snippets.

@Oleur
Last active February 2, 2024 00:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Oleur/acefc1c5502449fc9df6ad9b39644e24 to your computer and use it in GitHub Desktop.
Save Oleur/acefc1c5502449fc9df6ad9b39644e24 to your computer and use it in GitHub Desktop.
Get current Android activity and init an Android object from Unity
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