public void EnterLiveHallInGame() { if (this.androidBridge == IntPtr.Zero) { UnityEngine.Debug.LogError("androidBridge is null, enter LiveHallInGame failed!"); return; } jvalue[] args = AndroidJNIHelper.CreateJNIArgArray(new object[] { QGameKitAndroidBridge.getActivityContext() }); AndroidJNI.CallVoidMethod(this.androidBridge, QGameKitAndroidBridge.enterLiveHallInGameMethodID, args); }
private void initSDK() { IntPtr intPtr = AndroidJNI.FindClass("com/tencent/qgame/livesdk/bridge/Unity3D"); QGameKitAndroidBridge.constructorMethodID = AndroidJNI.GetMethodID(intPtr, "<init>", "(Landroid/content/Context;Ljava/lang/String;Ljava/lang/String;IIII)V"); if (QGameKitAndroidBridge.constructorMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find UnityBridge constructor."); return; } QGameKitAndroidBridge.setupMethodID = AndroidJNI.GetMethodID(intPtr, "setup", "(Lcom/tencent/qgame/livesdk/bridge/UserAccountListener;)Z"); if (QGameKitAndroidBridge.setupMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setup() method."); return; } QGameKitAndroidBridge.tearDownMethodID = AndroidJNI.GetMethodID(intPtr, "tearDown", "()V"); if (QGameKitAndroidBridge.tearDownMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find tearDown() method."); return; } QGameKitAndroidBridge.resetMethodID = AndroidJNI.GetMethodID(intPtr, "reset", "()Z"); if (QGameKitAndroidBridge.resetMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find reset() method."); return; } QGameKitAndroidBridge.startLiveBroadcastMethodID = AndroidJNI.GetMethodID(intPtr, "startLiveBroadcast", "(Ljava/lang/String;Ljava/lang/String;)Z"); if (QGameKitAndroidBridge.startLiveBroadcastMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find startLiveBroadcast() method."); return; } QGameKitAndroidBridge.stopLiveBroadcastMethodID = AndroidJNI.GetMethodID(intPtr, "stopLiveBroadcast", "()Z"); if (QGameKitAndroidBridge.stopLiveBroadcastMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find stopLiveBroadcast() method."); return; } QGameKitAndroidBridge.frameUpdatedMethodID = AndroidJNI.GetMethodID(intPtr, "frameUpdated", "()V"); if (QGameKitAndroidBridge.frameUpdatedMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find frameUpdated() method."); return; } QGameKitAndroidBridge.enterLiveHallMethodID = AndroidJNI.GetMethodID(intPtr, "enterLiveHall", "(Landroid/content/Context;)V"); if (QGameKitAndroidBridge.enterLiveHallMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find enterLiveHall() method."); return; } QGameKitAndroidBridge.enterLiveHallInGameMethodID = AndroidJNI.GetMethodID(intPtr, "enterLiveHallInGame", "(Landroid/content/Context;)V"); if (QGameKitAndroidBridge.enterLiveHallInGameMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find enterLiveHallInGameMethodID() method."); return; } QGameKitAndroidBridge.updateUserAccountMethodID = AndroidJNI.GetMethodID(intPtr, "updateUserAccount", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); if (QGameKitAndroidBridge.updateUserAccountMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find updateUserAccount() method."); return; } QGameKitAndroidBridge.getLiveBroadcastStatusMethodID = AndroidJNI.GetMethodID(intPtr, "getLiveBroadcastStatus", "()I"); if (QGameKitAndroidBridge.getLiveBroadcastStatusMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find getLiveBroadcastStatus() method."); return; } QGameKitAndroidBridge.getErrorCodeMethodID = AndroidJNI.GetMethodID(intPtr, "getErrorCode", "()I"); if (QGameKitAndroidBridge.getErrorCodeMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find getErrorCode() method."); return; } QGameKitAndroidBridge.setUserAccountListenerMethodID = AndroidJNI.GetMethodID(intPtr, "setUserAccountListener", "(Lcom/tencent/qgame/livesdk/bridge/UserAccountListener;)V"); if (QGameKitAndroidBridge.setUserAccountListenerMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setUserAccountListener() method."); return; } QGameKitAndroidBridge.setCommentReceiveDelegateMethodID = AndroidJNI.GetMethodID(intPtr, "setCommentReceiveListener", "(Lcom/tencent/qgame/livesdk/bridge/CommentReceiveListener;)V"); if (QGameKitAndroidBridge.setCommentReceiveDelegateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setCommentReceiveListener() method."); return; } QGameKitAndroidBridge.setLogDelegateMethodID = AndroidJNI.GetMethodID(intPtr, "setLogListener", "(Lcom/tencent/qgame/livesdk/bridge/LogListener;)V"); if (QGameKitAndroidBridge.setLogDelegateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setLogListener() method."); return; } QGameKitAndroidBridge.setLiveStatusChangedDelegateMethodID = AndroidJNI.GetMethodID(intPtr, "setLiveStatusChangedListener", "(Lcom/tencent/qgame/live/listener/OnLiveStatusChangedListener;)V"); if (QGameKitAndroidBridge.setLiveStatusChangedDelegateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setLiveStatusChangedListener() method."); return; } QGameKitAndroidBridge.setShareListenerMethodID = AndroidJNI.GetMethodID(intPtr, "setShareListener", "(Lcom/tencent/qgame/livesdk/bridge/ShareListener;)V"); if (QGameKitAndroidBridge.setShareListenerMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setShareListener() method."); return; } QGameKitAndroidBridge.setErrorCodeDelegateMethodID = AndroidJNI.GetMethodID(intPtr, "setErrorCodeListener", "(Lcom/tencent/qgame/live/listener/ErrorCodeListener;)V"); if (QGameKitAndroidBridge.setErrorCodeDelegateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setErrorCodeDelegateMethodID() method."); return; } QGameKitAndroidBridge.setWebViewStatusChangedDelegateMethodID = AndroidJNI.GetMethodID(intPtr, "setWebViewStatusChangedListener", "(Lcom/tencent/qgame/livesdk/bridge/WebViewStatusChangedListener;)V"); if (QGameKitAndroidBridge.setWebViewStatusChangedDelegateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setWebViewStatusChangedListener() method."); return; } QGameKitAndroidBridge.isLiveBroadcastSupportedMethodID = AndroidJNI.GetMethodID(intPtr, "isLiveBroadcastSupported", "()Z"); if (QGameKitAndroidBridge.isLiveBroadcastSupportedMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find isLiveBroadcastSupportedMethodID() method."); return; } QGameKitAndroidBridge.getVersionNameMethodID = AndroidJNI.GetMethodID(intPtr, "getVersionName", "()Ljava/lang/String;"); if (QGameKitAndroidBridge.getVersionNameMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find getVersionNameMethodID() method."); return; } QGameKitAndroidBridge.showCameraMethodID = AndroidJNI.GetMethodID(intPtr, "showCamera", "()Z"); if (QGameKitAndroidBridge.showCameraMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find showCameraMethodID() method."); return; } QGameKitAndroidBridge.hideCameraMethodID = AndroidJNI.GetMethodID(intPtr, "hideCamera", "()V"); if (QGameKitAndroidBridge.hideCameraMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find hideCameraMethodID() method."); return; } QGameKitAndroidBridge.setEnvironmentTypeMethodID = AndroidJNI.GetMethodID(intPtr, "setEnvironmentType", "(I)V"); if (QGameKitAndroidBridge.setEnvironmentTypeMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setEnvironmentTypeMethodID() method"); return; } QGameKitAndroidBridge.getLiveFrameRateMethodID = AndroidJNI.GetMethodID(intPtr, "getLiveFrameRate", "()I"); if (QGameKitAndroidBridge.getLiveFrameRateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find getLiveFrameRate() method"); return; } QGameKitAndroidBridge.notifyUserAccountMethodID = AndroidJNI.GetMethodID(intPtr, "notifyUserAccountUpdate", "()V"); if (QGameKitAndroidBridge.notifyUserAccountMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find notifyUserAccountMethodID() method."); return; } QGameKitAndroidBridge.doOnCreateMethodID = AndroidJNI.GetMethodID(intPtr, "doOnCreate", "()V"); if (QGameKitAndroidBridge.doOnCreateMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find doOnCreate() method"); return; } QGameKitAndroidBridge.doOnResumeMethodID = AndroidJNI.GetMethodID(intPtr, "doOnResume", "()V"); if (QGameKitAndroidBridge.doOnResumeMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find doOnResume() method"); return; } QGameKitAndroidBridge.doOnPauseMethodID = AndroidJNI.GetMethodID(intPtr, "doOnPause", "()V"); if (QGameKitAndroidBridge.doOnPauseMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find doOnPause() method"); return; } QGameKitAndroidBridge.doOnDestroyMethodID = AndroidJNI.GetMethodID(intPtr, "doOnDestroy", "()V"); if (QGameKitAndroidBridge.doOnDestroyMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find doOnDestroy() method"); return; } QGameKitAndroidBridge.doOnBackPressedMethodID = AndroidJNI.GetMethodID(intPtr, "doOnBackPressed", "()Z"); if (QGameKitAndroidBridge.doOnBackPressedMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find doOnBackPressed() method"); return; } QGameKitAndroidBridge.isSupportCameraMethodID = AndroidJNI.GetMethodID(intPtr, "isSupportCamera", "()Z"); if (QGameKitAndroidBridge.isSupportCameraMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find isSupportCamera() method"); return; } QGameKitAndroidBridge.shareLiveBroadcastMethodID = AndroidJNI.GetMethodID(intPtr, "shareLiveBroadcast", "()V"); if (QGameKitAndroidBridge.shareLiveBroadcastMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find shareLiveBroadcast() method"); return; } QGameKitAndroidBridge.isSupportLiveHallMethodID = AndroidJNI.GetMethodID(intPtr, "isSupportLiveHall", "()Z"); if (QGameKitAndroidBridge.isSupportLiveHallMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find isSupportLiveHall() method"); return; } QGameKitAndroidBridge.setDanmakuEnabledMethodID = AndroidJNI.GetMethodID(intPtr, "setDanmakuEnabled", "(Z)V"); if (QGameKitAndroidBridge.setDanmakuEnabledMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find setDanmakuEnabled() method"); return; } QGameKitAndroidBridge.showDanmakuMethodID = AndroidJNI.GetMethodID(intPtr, "showDanmaku", "()V"); if (QGameKitAndroidBridge.showDanmakuMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find showDanmaku() method"); return; } QGameKitAndroidBridge.hideDanmakuMethodID = AndroidJNI.GetMethodID(intPtr, "hideDanmaku", "()V"); if (QGameKitAndroidBridge.hideDanmakuMethodID == IntPtr.Zero) { UnityEngine.Debug.LogError("Can't find hideDanmaku() method"); return; } jvalue[] args = AndroidJNIHelper.CreateJNIArgArray(new object[] { QGameKitAndroidBridge.getActivityContext(), QGameKitAndroidBridge.gameID, QGameKitAndroidBridge.wnsID, Screen.width, Screen.height, Convert.ToInt32(QGameKitAndroidBridge.myCaptureType), Convert.ToInt32(QGameKitAndroidBridge.sdkEnvironmentType) }); IntPtr intPtr2 = AndroidJNI.NewObject(intPtr, QGameKitAndroidBridge.constructorMethodID, args); if (intPtr2 == IntPtr.Zero) { UnityEngine.Debug.LogError("--- Can't create Unity bridge object."); return; } this.androidBridge = AndroidJNI.NewGlobalRef(intPtr2); AndroidJNI.DeleteLocalRef(intPtr2); AndroidJNI.DeleteLocalRef(intPtr); UnityEngine.Debug.Log("--- grabFrameRate = " + this.grabFrameRate); this.frameInterval = 1f / (float)this.grabFrameRate; UnityEngine.Debug.Log("--- 1.0f / grabFrameRate = " + this.frameInterval); this.startTime = Time.time; this.isRunning = false; if (QGameKitAndroidBridge.myCaptureType == (QGameKit.CaptureType) 0) { if (QGameKitAndroidBridge.userAccountDelegate != null) { this.SetUserAccountDelegate(QGameKitAndroidBridge.userAccountDelegate); } UnityEngine.Debug.Log("CaptureType is zero, give up setup"); return; } if (this.setup()) { UnityEngine.Debug.Log("Native setup success."); } else { UnityEngine.Debug.LogError("Native setup failed!"); } }