|
@@ -1,22 +1,16 @@
|
|
|
package com.xplora.xpvideo.activity;
|
|
|
|
|
|
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.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.util.Log;
|
|
|
-import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
import android.view.WindowManager;
|
|
|
-import android.widget.Button;
|
|
|
import android.widget.ImageButton;
|
|
|
-import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
|
import com.juphoon.cloud.JCCall;
|
|
@@ -24,22 +18,18 @@ import com.juphoon.cloud.JCCallItem;
|
|
|
import com.juphoon.cloud.JCMediaDevice;
|
|
|
import com.juphoon.cloud.JCMediaDeviceVideoCanvas;
|
|
|
import com.xplora.xpvideo.R;
|
|
|
-import com.xplora.xpvideo.manager.DatabaseUtils;
|
|
|
import com.xplora.xpvideo.manager.VideoManager;
|
|
|
import com.xplora.xpvideo.model.ContactBean;
|
|
|
import com.xplora.xpvideo.observer.Listener;
|
|
|
-import com.xplora.xpvideo.utils.Constant;
|
|
|
import com.xplora.xpvideo.utils.ToolsUtils;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Timer;
|
|
|
|
|
|
public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
- private RelativeLayout mContentView = null;
|
|
|
- private RelativeLayout layoutWaitting = null;
|
|
|
- private LinearLayout layoutInvite = null;
|
|
|
- private LinearLayout layoutAccept = null;
|
|
|
- private LinearLayout layoutIng = null;
|
|
|
+ public final String TAG = "losion / xpvideo :" + getClass().getSimpleName();
|
|
|
+ private RelativeLayout mVideoLayout = null;
|
|
|
+ private RelativeLayout mInfoLayout = null;
|
|
|
private JCMediaDeviceVideoCanvas mLocalCanvas = null;
|
|
|
private JCMediaDeviceVideoCanvas mRemoteCanvas = null;
|
|
|
|
|
@@ -67,22 +57,11 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
mVideoManager.init(this, "TK_1ONFZ8pNwa"); //TK_QjZ0vC1tBa
|
|
|
}
|
|
|
|
|
|
- /*动态申请权限*/
|
|
|
- private void requestPermission() {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
|
|
|
- ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED ||
|
|
|
- ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
|
|
- requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA}, 1000);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void initView() {
|
|
|
- mContentView = findViewById(R.id.layout_video);
|
|
|
- ImageButton acceptCancel = findViewById(R.id.acceptCancel);
|
|
|
- ImageButton acceptAnswer = findViewById(R.id.acceptAnswer);
|
|
|
-
|
|
|
+ mVideoLayout = findViewById(R.id.layout_video);
|
|
|
+ mInfoLayout = findViewById(R.id.layout_info);
|
|
|
+ ImageButton acceptCancel = findViewById(R.id.cancelBtn);
|
|
|
+ ImageButton acceptAnswer = findViewById(R.id.answerBtn);
|
|
|
acceptCancel.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
@@ -97,6 +76,35 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+ /*动态申请权限*/
|
|
|
+ private void requestPermission() {
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
|
+ if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED ||
|
|
|
+ ContextCompat.checkSelfPermission(this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED ||
|
|
|
+ ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
|
|
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA}, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initSound() {
|
|
|
+// //设置音效池的属性,设置音效使用场景,设置音效类型
|
|
|
+// val audioAttributes = AudioAttributes.Builder()
|
|
|
+// .setLegacyStreamType(AudioManager.STREAM_MUSIC)
|
|
|
+// .build()
|
|
|
+// soundPool = SoundPool.Builder() //设置音效池属性
|
|
|
+// .setAudioAttributes(audioAttributes) //设置音效类型
|
|
|
+// .setMaxStreams(10)
|
|
|
+// .build()
|
|
|
+// soundMap[1] = soundPool!!.load(this, R.raw.video_call, 1)
|
|
|
+// soundMap[2] = soundPool!!.load(this, R.raw.video_cancel, 1)
|
|
|
+// soundPool!!.setOnLoadCompleteListener { soundPool, sampleId, status ->
|
|
|
+// if (sampleId == soundMap[1] && status == 0) {
|
|
|
+// soundPool.play(soundMap[1]!!, 0.6f, 0.6f, 1, -1, 1f)
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onLoginCallback(boolean isOK) {
|
|
|
if (isOK) {
|
|
@@ -143,83 +151,54 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
}
|
|
|
|
|
|
private void dealCanvas(JCCallItem item) {
|
|
|
- boolean change = false; // 是否有视频窗口变化
|
|
|
- if (mLocalCanvas == null && item.getUploadVideoStreamSelf()) {
|
|
|
- mLocalCanvas = mVideoManager.mMediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_SCREEN);
|
|
|
+ JCCallItem activeItem = mVideoManager.mCall.getCallItems().get(0);
|
|
|
+ int state = activeItem.getState();
|
|
|
+ Log.d(TAG, "dealCanvas: ");
|
|
|
+ Log.d(TAG, "dealCanvas: " + state);
|
|
|
+ if (activeItem.getState() == JCCall.STATE_INIT || activeItem.getState() == JCCall.STATE_PENDING) {
|
|
|
+ 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());
|
|
|
+ mVideoLayout.addView(mLocalCanvas.getVideoView(), 0);
|
|
|
+ }
|
|
|
+ } else if (mLocalCanvas != null && !item.getUploadVideoStreamSelf()) {
|
|
|
+ mVideoManager.mMediaDevice.stopVideo(mLocalCanvas);
|
|
|
+ mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mLocalCanvas = null;
|
|
|
+ }
|
|
|
+ } else if (activeItem.getState() == JCCall.STATE_TALKING) {
|
|
|
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;
|
|
|
- }
|
|
|
- });
|
|
|
+ mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mLocalCanvas = null;
|
|
|
}
|
|
|
- } 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);
|
|
|
if (mRemoteCanvas != null) {
|
|
|
mRemoteCanvas.getVideoView().setId(View.generateViewId());
|
|
|
- mContentView.addView(mRemoteCanvas.getVideoView(), 0);
|
|
|
+ mVideoLayout.addView(mRemoteCanvas.getVideoView(), 0);
|
|
|
}
|
|
|
- change = true;
|
|
|
} else if (mRemoteCanvas != null && !item.getUploadVideoStreamOther()) {
|
|
|
mVideoManager.mMediaDevice.stopVideo(mRemoteCanvas);
|
|
|
- mContentView.removeView(mRemoteCanvas.getVideoView());
|
|
|
+ mVideoLayout.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);
|
|
|
+ } else {
|
|
|
|
|
|
- } 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());
|
|
|
+ mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
mVideoManager.mMediaDevice.stopVideo(mLocalCanvas);
|
|
|
mLocalCanvas = null;
|
|
|
}
|
|
|
if (mRemoteCanvas != null) {
|
|
|
- mContentView.removeView(mRemoteCanvas.getVideoView());
|
|
|
+ mVideoLayout.removeView(mRemoteCanvas.getVideoView());
|
|
|
mVideoManager.mMediaDevice.stopVideo(mRemoteCanvas);
|
|
|
mRemoteCanvas = null;
|
|
|
}
|