MCPcopy Create free account
hub / github.com/defold/defold / PlatformInitialize

Function PlatformInitialize

engine/sound/src/sound_android.cpp:72–103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70namespace dmSound
71{
72 Result PlatformInitialize(dmConfigFile::HConfig config, const InitializeParams* params)
73 {
74 g_SoundManager.m_IsPhoneCallActive = false; // It will get updated by the call to the construct
75
76 dmAndroid::ThreadAttacher thread;
77 JNIEnv* environment = thread.GetEnv();
78 if (environment != NULL)
79 {
80 struct android_app* app = dmAndroid::GetAndroidApp();
81 assert(app);
82
83 jclass jni_class_NativeActivity = environment->FindClass("android/app/NativeActivity");
84 jmethodID jni_method_getClassLoader = environment->GetMethodID(jni_class_NativeActivity, "getClassLoader", "()Ljava/lang/ClassLoader;");
85 jobject jni_object_getClassLoader = environment->CallObjectMethod(app->activity->clazz, jni_method_getClassLoader);
86 jclass jni_class_ClassLoader = environment->FindClass("java/lang/ClassLoader");
87 jmethodID jni_method_loadClass = environment->GetMethodID(jni_class_ClassLoader, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;");
88
89 jstring jni_string_SoundManager = environment->NewStringUTF("com.defold.sound.SoundManager");
90 jclass jni_class_SoundManager = (jclass) environment->CallObjectMethod(jni_object_getClassLoader, jni_method_loadClass, jni_string_SoundManager);
91 jmethodID jni_constructor_SoundManager = environment->GetMethodID(jni_class_SoundManager, "<init>", "(Landroid/app/Activity;)V");
92
93 g_SoundManager.m_SoundManager = environment->NewGlobalRef(environment->NewObject(jni_class_SoundManager, jni_constructor_SoundManager, app->activity->clazz));
94 g_SoundManager.m_IsMusicPlaying = environment->GetMethodID(jni_class_SoundManager, "isMusicPlaying", "()Z");
95
96 environment->DeleteLocalRef(jni_string_SoundManager);
97 environment->DeleteLocalRef(jni_class_SoundManager);
98 environment->DeleteLocalRef(jni_class_ClassLoader);
99 environment->DeleteLocalRef(jni_object_getClassLoader);
100 environment->DeleteLocalRef(jni_class_NativeActivity);
101 }
102 return thread.Detach() ? RESULT_OK : RESULT_INIT_ERROR;
103 }
104
105 Result PlatformFinalize()
106 {

Callers 2

InitializeFunction · 0.70
InitializeFunction · 0.70

Calls 4

GetEnvMethod · 0.80
DetachMethod · 0.80
GetAndroidAppFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected