JLChen
2021-08-20 1b11947cc15245ae005a7cc8cc2f93c5660b0c23
HDLLinphoneSDKDemoNew/HDLLinphoneSDK/src/main/java/com/hdl/hdllinphonesdk/activity/HDLLinphoneIntercomActivity.java
@@ -28,6 +28,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;
/**
 * Linphone接听页面
 */
@@ -58,6 +62,9 @@
    private int callTime;//通话时间
    private CountDownTimer mCountDownTimer;
    //Linphone
    private CoreListenerStub mCoreListener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -92,11 +99,7 @@
            mCountDownTimer.cancel();
            mCountDownTimer = null;
        }
        if (mReceiver != null) {
            unregisterReceiver(mReceiver);
        }
        HDLLinphoneKit.getInstance().onDestroy();
        onDestroyLinphone();
        HDLLog.i(TAG,"onDestroy");
@@ -154,6 +157,7 @@
            view.setLayoutParams(layoutParams);
        }
    }
    /**
     * init OnClickListener
     */
@@ -243,7 +247,6 @@
    }
    /**
     * 开锁点击事件
     */
@@ -304,12 +307,14 @@
        iv_lp_unlock.setEnabled(false);
        startOpenDoorCountdown();
    }
    /**
     * 开启倒计时
     */
    void startOpenDoorCountdown() {
        mCountDownTimer.start();
    }
    /**
     * 通话记录开启倒计时
     */
@@ -317,12 +322,12 @@
        timer_lp_calltime.setBase(SystemClock.elapsedRealtime());//计时器清零
        timer_lp_calltime.start();
    }
    int getTimerCallTime(){
        int temp0 = Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[0]);
        int temp1 =Integer.parseInt(timer_lp_calltime.getText().toString().split(":")[1]);
        return temp0 * 60 + temp1;
    }
    /****************封装常用方法********/
@@ -352,23 +357,46 @@
    }
    /**********LinPhone**********/
    /**
     * initLinphone
     */
    void initLinphone(){
        IntentFilter intentFilter = new IntentFilter(RECEIVE_FINISH_VIDEO_ACTIVITY);
        mReceiver = new FinishVideoActivityReceiver();
        registerReceiver(mReceiver, intentFilter);
        HDLLinphoneKit.getInstance().setAndroidVideoWindow(video_lp_rendering, video_lp_rendering2);
    }
    public class FinishVideoActivityReceiver extends BroadcastReceiver {
        mCoreListener = new CoreListenerStub() {
        @Override
        public void onReceive(Context context, Intent intent) {
            HDLLinphoneIntercomActivity.this.finish();
            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_endOfCallStr));
                    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);
        }
    }
    private 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;
    }
}