// call this to render video stream from uid on this game object /** Sets the local or remote video. * * @note * - Do not call this method and {@link VideoSurface.SetForMultiChannelUser SetForMultiChannelUser} together. * - Ensure that you call this method in the main thread. * - Ensure that you call this method before binding VideoSurface.cs. * * @param uid The ID of the remote user, which is retrieved from {@link agora_gaming_rtc.OnUserJoinedHandler OnUserJoinedHandler}. The default value is 0, which means you can see the local video. */ public void SetForUser(uint uid) { if (IRtcEngine.QueryEngine() != null) { mUid = uid; IRtcEngine.QueryEngine().GetVideoRender().AddUserVideoInfo(mUid, 0); } mUid = uid; Debug.Log("Set uid " + uid + " for " + gameObject.name); }
/** Sets the local or remote video of users in multiple channels. * * @since v3.0.1 * * @note * - This method only applies to the multi-channel feature. * - Do not call this method and {@link VideoSurface.SetForUser SetForUser} together. * - Ensure that you call this method in the main thread. * - Ensure that you call this method before binding VideoSurface.cs. * * @param channelId The channel name. * @param uid The ID of the remote user, which is retrieved from {@link agora_gaming_rtc.OnUserJoinedHandler OnUserJoinedHandler}. The default value is 0, which means you can see the local video. */ public void SetForMultiChannelUser(string channelId, uint uid) { if (IRtcEngine.QueryEngine() != null) { isMultiChannelWant = true; mUid = uid; mChannelId = channelId; IRtcEngine.QueryEngine().GetVideoRender().AddUserVideoInfo(mChannelId, mUid, 0); } else { Debug.LogError("Plear init agora engine first"); } }
void OnDestroy() { Debug.Log("VideoSurface OnDestroy"); if (videoRender != null && IRtcEngine.QueryEngine() != null) { if (isMultiChannelWant) { if (mUid == 0) { videoRender.RemoveUserVideoInfo(mUid); } else { videoRender.RemoveUserVideoInfo(mChannelId, mUid); } } else { videoRender.RemoveUserVideoInfo(mUid); } } if (data != IntPtr.Zero) { Marshal.FreeHGlobal(data); data = IntPtr.Zero; } if (nativeTexture != null) { Destroy(nativeTexture); nativeTexture = null; } mRenderer = null; }