From 1b11947cc15245ae005a7cc8cc2f93c5660b0c23 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期五, 20 八月 2021 17:17:43 +0800 Subject: [PATCH] 2021-08-20 1.优化更新 --- HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java | 59 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 42 insertions(+), 17 deletions(-) diff --git a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java index a5c8cb3..5b86194 100644 --- a/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java +++ b/HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java @@ -27,6 +27,10 @@ import com.hdl.hdllinphonesdk.utils.HDLImageUtils; import com.hdl.hdllinphonesdk.utils.HDLLog; +import org.linphone.core.Call; +import org.linphone.core.Core; +import org.linphone.core.CoreListenerStub; + /** *鐩戣椤甸潰 */ @@ -47,6 +51,9 @@ private TextureView video_lp_rendering2; private CountDownTimer mCountDownTimer; + + //Linphone + private CoreListenerStub mCoreListener; @Override protected void onCreate(Bundle savedInstanceState) { @@ -79,10 +86,7 @@ mCountDownTimer = null; } - if (mReceiver != null) { - unregisterReceiver(mReceiver); - } - HDLLinphoneKit.getInstance().onDestroy(); + onDestroyLinphone(); HDLLog.i(TAG,"onDestroy"); @@ -287,23 +291,44 @@ } /**********LinPhone**********/ - void initLinphone(){ - IntentFilter intentFilter = new IntentFilter(RECEIVE_FINISH_VIDEO_ACTIVITY); - mReceiver = new HDLLinphoneMonitorActivity.FinishVideoActivityReceiver(); - registerReceiver(mReceiver, intentFilter); - HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2); + /** + * initLinphone + */ + void initLinphone() { + mCoreListener = new CoreListenerStub() { + @Override + public void onCallStateChanged(Core core, Call call, Call.State state, String message) { + if (state == Call.State.End || state == Call.State.Released) { + // Once call is finished (end state), terminate the activity + // We also check for released state (called a few seconds later) just in case + // we missed the first one + showToast(getString(R.string.lp_endMonitoringStr)); + finish(); + } + } + }; + + Core core = HDLLinphoneKit.getInstance().getCore(); + // We need to tell the core in which to display what + if (core != null) { + core.setNativeVideoWindowId(video_lp_rendering); + core.setNativePreviewWindowId(video_lp_rendering2); + // Listen for call state changes + core.addListener(mCoreListener); + } } /** - * 椤甸潰鍏抽棴骞挎挱鐩戝惉 + * onDestroyLinphone */ - public class FinishVideoActivityReceiver extends BroadcastReceiver { - @Override - public void onReceive(Context context, Intent intent) { - HDLLinphoneMonitorActivity.this.finish(); + void onDestroyLinphone(){ + Core core = HDLLinphoneKit.getInstance().getCore(); + if (core != null) { + core.removeListener(mCoreListener); + core.setNativeVideoWindowId(null); + core.setNativePreviewWindowId(null); } + video_lp_rendering = null; + video_lp_rendering2 = null; } - private HDLLinphoneMonitorActivity.FinishVideoActivityReceiver mReceiver; - public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity"; - } \ No newline at end of file -- Gitblit v1.8.0