From 1697a5c0a1d40e756738d1f99d496c6e33b3fd52 Mon Sep 17 00:00:00 2001
From: lss <lsc@hdlchina.com.cn>
Date: 星期二, 28 六月 2022 14:09:38 +0800
Subject: [PATCH] 2022-6-28
---
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneMonitorActivity.java | 97 +++++++++++++++++++++++++++++++-----------------
1 files changed, 63 insertions(+), 34 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 cefa1be..8ce8269 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
@@ -25,9 +25,14 @@
import com.hdl.hdllinphonesdk.R;
import com.hdl.hdllinphonesdk.callback.OnLPOpenDoorCallBack;
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;
/**
-*鐩戣椤甸潰
+ * 鐩戣椤甸潰
*/
public class HDLLinphoneMonitorActivity extends LPCheckPermissionsActivity implements View.OnClickListener {
private static final String TAG = "HDLLinphoneMonitorActivity";
@@ -46,6 +51,9 @@
private TextureView video_lp_rendering2;
private CountDownTimer mCountDownTimer;
+
+ //Linphone
+ private CoreListenerStub mCoreListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -70,6 +78,8 @@
@Override
protected void onDestroy() {
super.onDestroy();
+ //1.鎸傛柇
+ HDLLinphoneKit.getInstance().hangUp();
HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(null);
@@ -78,15 +88,11 @@
mCountDownTimer = null;
}
- if (mReceiver != null) {
- unregisterReceiver(mReceiver);
- }
- HDLLinphoneKit.getInstance().onDestroy();
+ onDestroyLinphone();
- Log.i(TAG,"onDestroy");
+ HDLLog.i(TAG, "onDestroy");
}
-
/**
* initView
@@ -104,17 +110,17 @@
video_lp_rendering = findViewById(R.id.video_lp_rendering);
video_lp_rendering2 = findViewById(R.id.video_lp_rendering2);
- setWidthHeightWithRatio(ll_video_lp_rendering,16,9);
+ setWidthHeightWithRatio(ll_video_lp_rendering, 16, 9);
}
/**
* initData
*/
- private void initData(){
+ private void initData() {
Bundle extras = getIntent().getExtras();
- if(extras != null){
- String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME);
- if(!TextUtils.isEmpty(titleName)){
+ if (extras != null) {
+ String titleName = extras.getString(HDLLinphoneKit.KEY_TITLE_NAME);
+ if (!TextUtils.isEmpty(titleName)) {
tv_lp_title.setText(titleName);
}
}
@@ -137,6 +143,7 @@
view.setLayoutParams(layoutParams);
}
}
+
/**
* init OnClickListener
*/
@@ -153,7 +160,7 @@
/**
* 鍒濆鍖栧紑闂ㄥ洖璋冧簨浠�
*/
- void initCallBack(){
+ void initCallBack() {
HDLLinphoneKit.getInstance().setOpenOpenDoorCallBack(new OnLPOpenDoorCallBack() {
@Override
public void onOpenSuccess() {
@@ -170,9 +177,9 @@
/**
* 鍒濆鍖栧紑閿佸睆钄藉�掕鏃�
*/
- void initCountDownTimer(){
+ void initCountDownTimer() {
- mCountDownTimer = new CountDownTimer(10*1000, 1000) {
+ mCountDownTimer = new CountDownTimer(10 * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
if (!HDLLinphoneMonitorActivity.this.isFinishing()) {
@@ -188,9 +195,7 @@
// showToast("寮�閿乷nFinish");
iv_lp_unlock.setEnabled(true);
}
-
};
-//
}
@Override
@@ -214,11 +219,11 @@
private void onClickScreenshot() {
// Bitmap img = HDLImageUtils.createViewBitmap(video_lp_rendering);
Bitmap img = video_lp_rendering.getBitmap();
- boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img);
+ boolean isSuccess = HDLImageUtils.saveImageToGallery(this, img);
- if(isSuccess){
+ if (isSuccess) {
showToast(getString(R.string.lp_saveToTheAlbumsStr));
- }else {
+ } else {
showToast(getString(R.string.lp_operationFailedStr));
}
}
@@ -252,6 +257,7 @@
iv_lp_unlock.setEnabled(false);
startOpenDoorCountdown();
}
+
/**
* 寮�鍚�掕鏃�
*/
@@ -286,22 +292,45 @@
}
/**********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();
+ }
+ }
+ };
-
- public class FinishVideoActivityReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- HDLLinphoneMonitorActivity.this.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);
+ core.enableMic(false);//鍏抽棴楹﹀厠椋�
}
}
- private HDLLinphoneMonitorActivity.FinishVideoActivityReceiver mReceiver;
- public static final String RECEIVE_FINISH_VIDEO_ACTIVITY = "receive_finish_video_activity";
-
+ /**
+ * onDestroyLinphone
+ */
+ 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;
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0