|
@@ -3,6 +3,7 @@ package com.xplora.xpvideo.activity;
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
import androidx.core.content.ContextCompat;
|
|
|
import android.Manifest;
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.content.pm.PackageManager;
|
|
|
import android.os.Build;
|
|
@@ -11,7 +12,10 @@ import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
|
import android.widget.ImageButton;
|
|
|
+import android.widget.ImageView;
|
|
|
import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
|
|
|
import com.juphoon.cloud.JCCall;
|
|
|
import com.juphoon.cloud.JCCallItem;
|
|
@@ -23,43 +27,50 @@ import com.xplora.xpvideo.model.ContactBean;
|
|
|
import com.xplora.xpvideo.observer.Listener;
|
|
|
import com.xplora.xpvideo.utils.ToolsUtils;
|
|
|
|
|
|
+import org.w3c.dom.Text;
|
|
|
+
|
|
|
import java.util.List;
|
|
|
import java.util.Timer;
|
|
|
+import java.util.TimerTask;
|
|
|
|
|
|
public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
public final String TAG = "losion / xpvideo :" + getClass().getSimpleName();
|
|
|
- private RelativeLayout mVideoLayout = null;
|
|
|
- private RelativeLayout mInfoLayout = null;
|
|
|
+
|
|
|
+ public VideoManager mVideoManager = new VideoManager();
|
|
|
private JCMediaDeviceVideoCanvas mLocalCanvas = null;
|
|
|
private JCMediaDeviceVideoCanvas mRemoteCanvas = null;
|
|
|
|
|
|
- private Timer mTimeOverTimer = null;
|
|
|
- private Timer mTimerTask = null;
|
|
|
- private Timer mCallInfoTimer = null;
|
|
|
+ private RelativeLayout mVideoLayout = null;
|
|
|
+ private RelativeLayout mInfoLayout = null;
|
|
|
+ private ImageView mIconView = null;
|
|
|
+ private TextView mNameText = null;
|
|
|
+ private TextView mHintText = null;
|
|
|
+
|
|
|
+ private Timer mTimeoutTimer = null;
|
|
|
+ private Timer mTalkingTimer = null;
|
|
|
+ private int mTimeCount = 0;
|
|
|
|
|
|
+ //0:呼入 1:呼出
|
|
|
private int mVideoType = 0;
|
|
|
private String mVideoId = "f471b2a1-0e5e-4796-8949-7a4cfeac5df3";
|
|
|
private ContactBean mContactBean = new ContactBean();
|
|
|
|
|
|
- public VideoManager mVideoManager = new VideoManager();
|
|
|
-
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
-
|
|
|
requestPermission();
|
|
|
initView();
|
|
|
-
|
|
|
- //mVideoType = getIntent().getIntExtra(Constant.EXTRA_VIDEO_TYPE, 0);
|
|
|
- //mVideoId = getIntent().getStringExtra(Constant.EXTRA_VIDEO_ID);
|
|
|
- //mContactBean = new DatabaseUtils().loadContact(mVideoId);
|
|
|
+ initData();
|
|
|
mVideoManager.init(this, "TK_1ONFZ8pNwa"); //TK_QjZ0vC1tBa
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
|
mVideoLayout = findViewById(R.id.layout_video);
|
|
|
mInfoLayout = findViewById(R.id.layout_info);
|
|
|
+ mIconView = findViewById(R.id.iconIv);
|
|
|
+ mNameText = findViewById(R.id.nameTv);
|
|
|
+ mHintText = findViewById(R.id.hintTv);
|
|
|
ImageButton acceptCancel = findViewById(R.id.cancelBtn);
|
|
|
ImageButton acceptAnswer = findViewById(R.id.answerBtn);
|
|
|
acceptCancel.setOnClickListener(new View.OnClickListener() {
|
|
@@ -76,33 +87,14 @@ 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 initData() {
|
|
|
+ //mVideoType = getIntent().getIntExtra(Constant.EXTRA_VIDEO_TYPE, 0);
|
|
|
+ //mVideoId = getIntent().getStringExtra(Constant.EXTRA_VIDEO_ID);
|
|
|
+ //mContactBean = new DatabaseUtils().loadContact(mVideoId);
|
|
|
|
|
|
- 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)
|
|
|
-// }
|
|
|
-// }
|
|
|
+ ToolsUtils.setImageView(mIconView, "", 0, R.drawable.default_avatar);
|
|
|
+ mNameText.setText("这显示名字");
|
|
|
+ mHintText.setText(mVideoType == 0 ? R.string.invite : R.string.calling);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -125,37 +117,30 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
public void onCallItemUpdate() {
|
|
|
List<JCCallItem> callItems = mVideoManager.mCall.getCallItems();
|
|
|
if (callItems.size() == 0) {
|
|
|
- stopCallInfoTimer();
|
|
|
- stopTimeOverTimer();
|
|
|
+ stopTimeoutTimer();
|
|
|
+ stopTalkingTimer();
|
|
|
removeCanvas();
|
|
|
finish();
|
|
|
} else {
|
|
|
- startCallInfoTimer();
|
|
|
+ startTimeoutTimer();
|
|
|
JCCallItem item = mVideoManager.getActiveCall();
|
|
|
if (item == null) {
|
|
|
return;
|
|
|
}
|
|
|
boolean needAnswer = item.getDirection() == JCCall.DIRECTION_IN && item.getState() == JCCall.STATE_PENDING;
|
|
|
if (item.getVideo()) {
|
|
|
- dealCanvas(item);
|
|
|
+ updateLayout(item);
|
|
|
} else {
|
|
|
removeCanvas();
|
|
|
}
|
|
|
- //dealNeedAnswerCall();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void onCallItemRemove() {
|
|
|
- finish();
|
|
|
- }
|
|
|
-
|
|
|
- private void dealCanvas(JCCallItem item) {
|
|
|
+ private void updateLayout(JCCallItem item) {
|
|
|
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) {
|
|
|
+ Log.d(TAG, "updateLayout: " + state);
|
|
|
+ if (state == JCCall.STATE_INIT || state == JCCall.STATE_PENDING) {
|
|
|
if (mLocalCanvas == null && item.getUploadVideoStreamSelf()) {
|
|
|
mLocalCanvas = mVideoManager.mMediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_SCREEN);
|
|
|
if (mLocalCanvas != null) {
|
|
@@ -168,13 +153,15 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
mLocalCanvas = null;
|
|
|
}
|
|
|
- } else if (activeItem.getState() == JCCall.STATE_TALKING) {
|
|
|
+ } else if (state == JCCall.STATE_CONNECTING) {
|
|
|
+ mHintText.setText(R.string.connecting);
|
|
|
+ } else if (state == JCCall.STATE_TALKING) {
|
|
|
if (mLocalCanvas != null) {
|
|
|
mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
mLocalCanvas = null;
|
|
|
}
|
|
|
if (mRemoteCanvas == null && item.getUploadVideoStreamOther()) {
|
|
|
- stopTimeOverTimer();
|
|
|
+ startTalkingTimer();
|
|
|
mVideoManager.mMediaDevice.enableSpeaker(true);
|
|
|
mRemoteCanvas = mVideoManager.mMediaDevice.startVideo(item.getRenderId(), JCMediaDevice.RENDER_FULL_CONTENT);
|
|
|
if (mRemoteCanvas != null) {
|
|
@@ -186,8 +173,6 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
mVideoLayout.removeView(mRemoteCanvas.getVideoView());
|
|
|
mRemoteCanvas = null;
|
|
|
}
|
|
|
- } else {
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -204,6 +189,11 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onCallItemRemove() {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
private void moveView(View view, Float rawX, Float rawY) {
|
|
|
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams)view.getLayoutParams();
|
|
|
WindowManager wm = (WindowManager)this.getSystemService(WINDOW_SERVICE);
|
|
@@ -228,41 +218,94 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
view.setLayoutParams(params);
|
|
|
}
|
|
|
|
|
|
- private void startCallInfoTimer() {
|
|
|
- if (mCallInfoTimer != null) {
|
|
|
- stopCallInfoTimer();
|
|
|
+ /*动态申请权限*/
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
- mCallInfoTimer = new Timer();
|
|
|
}
|
|
|
|
|
|
- private void stopCallInfoTimer() {
|
|
|
- if (mCallInfoTimer != null) {
|
|
|
- mCallInfoTimer.cancel();
|
|
|
- mCallInfoTimer = null;
|
|
|
+ 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)
|
|
|
+// }
|
|
|
+// }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startTimeoutTimer() {
|
|
|
+ if (mTimeoutTimer != null) {
|
|
|
+ stopTimeoutTimer();
|
|
|
}
|
|
|
+ mTimeoutTimer = new Timer();
|
|
|
+ mTimeoutTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+
|
|
|
+ }
|
|
|
+ }, 1000 );
|
|
|
}
|
|
|
|
|
|
- private void startTimeOverTimer() {
|
|
|
- if (mTimeOverTimer != null) {
|
|
|
- stopTimeOverTimer();
|
|
|
+ private void stopTimeoutTimer() {
|
|
|
+ if (mTimeoutTimer != null) {
|
|
|
+ mTimeoutTimer.cancel();
|
|
|
+ mTimeoutTimer = null;
|
|
|
}
|
|
|
- mTimeOverTimer = new Timer();
|
|
|
}
|
|
|
|
|
|
- private void stopTimeOverTimer() {
|
|
|
- if (mTimeOverTimer != null) {
|
|
|
- mTimeOverTimer.cancel();
|
|
|
- mTimeOverTimer = null;
|
|
|
+ private void startTalkingTimer() {
|
|
|
+ if (mTalkingTimer != null) {
|
|
|
+ stopTalkingTimer();
|
|
|
}
|
|
|
- if (mTimerTask != null) {
|
|
|
- mTimerTask.cancel();
|
|
|
- mTimerTask = null;
|
|
|
+ mTalkingTimer = new Timer();
|
|
|
+ mTalkingTimer.schedule(new TimerTask() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ refreshTimeLabel();
|
|
|
+ }
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void stopTalkingTimer() {
|
|
|
+ if (mTalkingTimer != null) {
|
|
|
+ mTalkingTimer.cancel();
|
|
|
+ mTalkingTimer = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("DefaultLocale")
|
|
|
+ private void refreshTimeLabel() {
|
|
|
+ long hours = mTimeCount / 3600;
|
|
|
+ mTimeCount %= 3600;
|
|
|
+ long minutes = mTimeCount / 60;
|
|
|
+ long second = mTimeCount %= 60;
|
|
|
+ String text = hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, second) : String.format("%02d:%02d", minutes, second);
|
|
|
+ mHintText.setText(text);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void toast(String content) {
|
|
|
+ Toast t = Toast.makeText(this, content, Toast.LENGTH_SHORT);
|
|
|
+ t.show();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
-
|
|
|
+ stopTimeoutTimer();
|
|
|
+ stopTalkingTimer();
|
|
|
}
|
|
|
}
|