|
@@ -1,13 +1,38 @@
|
|
|
package com.xplora.xpvideo;
|
|
|
|
|
|
+import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
+import androidx.constraintlayout.widget.ConstraintSet;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
import android.Manifest;
|
|
|
import android.app.Activity;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+
|
|
|
+import com.juphoon.cloud.JCCall;
|
|
|
+import com.juphoon.cloud.JCCallItem;
|
|
|
+import com.juphoon.cloud.JCMediaDevice;
|
|
|
+import com.juphoon.cloud.JCMediaDeviceVideoCanvas;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Timer;
|
|
|
|
|
|
public class MainActivity extends Activity {
|
|
|
+ public VideoManager mVideoManager = null;
|
|
|
+ private ConstraintLayout mContentView = null;
|
|
|
+ private View mVideoIn = null;
|
|
|
+ private View mVideoInCall = null;
|
|
|
+ private View mInvite = null;
|
|
|
+ private View mAccepte = null;
|
|
|
+ private JCMediaDeviceVideoCanvas mLocalCanvas = null;
|
|
|
+ private JCMediaDeviceVideoCanvas mRemoteCanvas = null;
|
|
|
+
|
|
|
+ private Timer mTimeOverTimer = null;
|
|
|
+ private Timer mTimerTask = null;
|
|
|
+ private Timer mCallInfoTimer = null;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -28,4 +53,164 @@ public class MainActivity extends Activity {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private void updateUI() {
|
|
|
+ List<JCCallItem> callItems = mVideoManager.mCall.getCallItems();
|
|
|
+ if (callItems.size() == 0) {
|
|
|
+ stopCallInfoTimer();
|
|
|
+ stopTimeOverTimer();
|
|
|
+ removeCanvas();
|
|
|
+ finish();
|
|
|
+ } else {
|
|
|
+ startCallInfoTimer();
|
|
|
+ JCCallItem item = mVideoManager.getActiveCall();
|
|
|
+ if (item == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean needAnswer = item.getDirection() == JCCall.DIRECTION_IN && item.getState() == JCCall.STATE_PENDING;
|
|
|
+ mVideoIn.setVisibility(item.getVideo() && needAnswer ? View.VISIBLE : View.INVISIBLE);
|
|
|
+ mInvite.setVisibility(item.getVideo() && needAnswer ? View.VISIBLE : View.INVISIBLE);
|
|
|
+ mVideoInCall.setVisibility(item.getVideo() && !needAnswer ? View.VISIBLE : View.INVISIBLE);
|
|
|
+ mAccepte.setVisibility(item.getVideo() && !needAnswer ? View.VISIBLE : View.INVISIBLE);
|
|
|
+ if (item.getVideo()) {
|
|
|
+ dealCanvas(item);
|
|
|
+ } else {
|
|
|
+ removeCanvas();
|
|
|
+ }
|
|
|
+ //dealNeedAnswerCall();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void dealCanvas(JCCallItem item) {
|
|
|
+ boolean change = false; // 是否有视频窗口变化
|
|
|
+ if (mLocalCanvas == null && item.getUploadVideoStreamSelf()) {
|
|
|
+ mLocalCanvas = mVideoManager.mMediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_SCREEN);
|
|
|
+ if (mLocalCanvas != null) {
|
|
|
+ mLocalCanvas.getVideoView().setZOrderMediaOverlay(true);
|
|
|
+ mLocalCanvas.getVideoView().setId(View.generateViewId());
|
|
|
+ mContentView.addView(mLocalCanvas.getVideoView(), 0);
|
|
|
+ mContentView.setOnTouchListener(new View.OnTouchListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onTouch(View v, MotionEvent event) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else if (mLocalCanvas != null && !item.getUploadVideoStreamSelf()) {
|
|
|
+ mVideoManager.mMediaDevice.stopVideo(mLocalCanvas);
|
|
|
+ mContentView.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mLocalCanvas = null;
|
|
|
+ change = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (item.getState() == JCCall.STATE_TALKING) {
|
|
|
+ if (mRemoteCanvas == null && item.getUploadVideoStreamOther()) {
|
|
|
+ stopTimeOverTimer();
|
|
|
+ mVideoManager.mMediaDevice.enableSpeaker(true);
|
|
|
+ mRemoteCanvas = mVideoManager.mMediaDevice.startVideo(item.getRenderId(), JCMediaDevice.RENDER_FULL_CONTENT);
|
|
|
+ //mRemoteCanvas. videoView.id = View.generateViewId()
|
|
|
+ if (mRemoteCanvas != null) {
|
|
|
+ mContentView.addView(mRemoteCanvas.getVideoView(), 0);
|
|
|
+ }
|
|
|
+ change = true;
|
|
|
+ } else if (mRemoteCanvas != null && !item.getUploadVideoStreamOther()) {
|
|
|
+ mVideoManager.mMediaDevice.stopVideo(mRemoteCanvas);
|
|
|
+ mContentView.removeView(mRemoteCanvas.getVideoView());
|
|
|
+ mRemoteCanvas = null;
|
|
|
+ change = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理视频窗口大小
|
|
|
+ if (change) {
|
|
|
+ if (mLocalCanvas != null && mRemoteCanvas != null) {
|
|
|
+ mContentView.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mContentView.removeView(mRemoteCanvas.getVideoView());
|
|
|
+ mContentView.addView(mRemoteCanvas.getVideoView(), 0);
|
|
|
+ mContentView.addView(mLocalCanvas.getVideoView(), 1);
|
|
|
+ ConstraintSet constraintSet = new ConstraintSet();
|
|
|
+ constraintSet.clone(mContentView);
|
|
|
+ constraintSet.constrainWidth(mLocalCanvas.getVideoView().getId(), ToolUtil.dip2px(this, 120f));
|
|
|
+ constraintSet.constrainHeight(mLocalCanvas.getVideoView().getId(), ToolUtil.dip2px(this, 160f));
|
|
|
+ constraintSet.connect(
|
|
|
+ mLocalCanvas.getVideoView().getId(),
|
|
|
+ ConstraintSet.START,
|
|
|
+ ConstraintSet.PARENT_ID,
|
|
|
+ ConstraintSet.START,
|
|
|
+ ToolUtil.dip2px(this, 8f)
|
|
|
+ );
|
|
|
+ constraintSet.connect(
|
|
|
+ mLocalCanvas.getVideoView().getId(),
|
|
|
+ ConstraintSet.TOP,
|
|
|
+ ConstraintSet.PARENT_ID,
|
|
|
+ ConstraintSet.TOP,
|
|
|
+ ToolUtil.dip2px(this, 24f)
|
|
|
+ );
|
|
|
+ constraintSet.applyTo(mContentView);
|
|
|
+ } else if (mLocalCanvas != null) {
|
|
|
+ mContentView.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mContentView.addView(
|
|
|
+ mLocalCanvas.getVideoView(), 0,
|
|
|
+ new ConstraintLayout.LayoutParams(
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
+ )
|
|
|
+ );
|
|
|
+ } else if (mRemoteCanvas != null) {
|
|
|
+ mContentView.removeView(mRemoteCanvas.getVideoView());
|
|
|
+ mContentView.addView(
|
|
|
+ mRemoteCanvas.getVideoView(), 0,
|
|
|
+ new ConstraintLayout.LayoutParams(
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void removeCanvas() {
|
|
|
+ if (mLocalCanvas != null) {
|
|
|
+ mContentView.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mVideoManager.mMediaDevice.stopVideo(mLocalCanvas);
|
|
|
+ mLocalCanvas = null;
|
|
|
+ }
|
|
|
+ if (mRemoteCanvas != null) {
|
|
|
+ mContentView.removeView(mRemoteCanvas.getVideoView());
|
|
|
+ mVideoManager.mMediaDevice.stopVideo(mRemoteCanvas);
|
|
|
+ mRemoteCanvas = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startCallInfoTimer() {
|
|
|
+ if (mCallInfoTimer != null) {
|
|
|
+ stopCallInfoTimer();
|
|
|
+ }
|
|
|
+ mCallInfoTimer = new Timer();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopCallInfoTimer() {
|
|
|
+ if (mCallInfoTimer != null) {
|
|
|
+ mCallInfoTimer.cancel();
|
|
|
+ mCallInfoTimer = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startTimeOverTimer() {
|
|
|
+ if (mTimeOverTimer != null) {
|
|
|
+ stopTimeOverTimer();
|
|
|
+ }
|
|
|
+ mTimeOverTimer = new Timer();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopTimeOverTimer() {
|
|
|
+ if (mTimeOverTimer != null) {
|
|
|
+ mTimeOverTimer.cancel();
|
|
|
+ mTimeOverTimer = null;
|
|
|
+ }
|
|
|
+ if (mTimerTask != null) {
|
|
|
+ mTimerTask.cancel();
|
|
|
+ mTimerTask = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|