|
@@ -6,8 +6,10 @@ import android.Manifest;
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.app.Activity;
|
|
|
import android.content.pm.PackageManager;
|
|
|
+import android.media.MediaPlayer;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
@@ -22,13 +24,19 @@ 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.MediaPlayerUtils;
|
|
|
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.Macros;
|
|
|
import com.xplora.xpvideo.utils.ToolsUtils;
|
|
|
|
|
|
import org.w3c.dom.Text;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.sql.Time;
|
|
|
import java.util.List;
|
|
|
import java.util.Timer;
|
|
|
import java.util.TimerTask;
|
|
@@ -37,6 +45,8 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
public final String TAG = "losion / xpvideo :" + getClass().getSimpleName();
|
|
|
|
|
|
public VideoManager mVideoManager = new VideoManager();
|
|
|
+ public MediaPlayerUtils mMediaPlayerUtils = new MediaPlayerUtils();
|
|
|
+
|
|
|
private JCMediaDeviceVideoCanvas mLocalCanvas = null;
|
|
|
private JCMediaDeviceVideoCanvas mRemoteCanvas = null;
|
|
|
|
|
@@ -52,7 +62,8 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
|
|
|
//0:呼入 1:呼出
|
|
|
private int mVideoType = 0;
|
|
|
- private String mVideoId = "f471b2a1-0e5e-4796-8949-7a4cfeac5df3";
|
|
|
+ private String mVideoId = "";
|
|
|
+ private String mTicket = "TK_1ONFZ8pNwa";
|
|
|
private ContactBean mContactBean = new ContactBean();
|
|
|
|
|
|
@Override
|
|
@@ -62,7 +73,7 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
requestPermission();
|
|
|
initView();
|
|
|
initData();
|
|
|
- mVideoManager.init(this, "TK_1ONFZ8pNwa"); //TK_QjZ0vC1tBa
|
|
|
+ mVideoManager.init(this, mTicket);
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
@@ -88,18 +99,25 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
}
|
|
|
|
|
|
private void initData() {
|
|
|
- //mVideoType = getIntent().getIntExtra(Constant.EXTRA_VIDEO_TYPE, 0);
|
|
|
- //mVideoId = getIntent().getStringExtra(Constant.EXTRA_VIDEO_ID);
|
|
|
- //mContactBean = new DatabaseUtils().loadContact(mVideoId);
|
|
|
+ if (Macros.DEBUG) {
|
|
|
+ mVideoType = 1;
|
|
|
+ mVideoId = "3523b1d1-8543-43d9-92c9-df663a3f147d";
|
|
|
+ } else {
|
|
|
+ mVideoType = getIntent().getIntExtra(Constant.EXTRA_VIDEO_TYPE, 0);
|
|
|
+ mVideoId = getIntent().getStringExtra(Constant.EXTRA_VIDEO_ID);
|
|
|
+ }
|
|
|
+ mContactBean = new DatabaseUtils().loadContact(mVideoId);
|
|
|
|
|
|
- ToolsUtils.setImageView(mIconView, "", 0, R.drawable.default_avatar);
|
|
|
- mNameText.setText("这显示名字");
|
|
|
+ ToolsUtils.setImageView(mIconView, mContactBean.profilePath, 0, R.drawable.default_avatar);
|
|
|
+ mNameText.setText(mContactBean.name);
|
|
|
mHintText.setText(mVideoType == 0 ? R.string.invite : R.string.calling);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onLoginCallback(boolean isOK) {
|
|
|
+ Log.d(TAG, "onLoginCallback: " + isOK);
|
|
|
if (isOK) {
|
|
|
+ //呼出
|
|
|
if (mVideoType == 1) {
|
|
|
mVideoManager.call(mVideoId);
|
|
|
}
|
|
@@ -109,20 +127,19 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
@Override
|
|
|
public void onCallItemAdd(JCCallItem item) {
|
|
|
if (item.getDirection() == JCCall.DIRECTION_IN && item.getVideo()) {
|
|
|
- // 2. 做出相应的处理,如在界面上显示“振铃中”
|
|
|
+ Log.d(TAG, "onCallItemAdd: " + item.getUserId());
|
|
|
}
|
|
|
+
|
|
|
+ // 2. 做出相应的处理,如在界面上显示“振铃中”
|
|
|
+ mMediaPlayerUtils.playSound(this, R.raw.video_call, true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCallItemUpdate() {
|
|
|
List<JCCallItem> callItems = mVideoManager.mCall.getCallItems();
|
|
|
if (callItems.size() == 0) {
|
|
|
- stopTimeoutTimer();
|
|
|
- stopTalkingTimer();
|
|
|
- removeCanvas();
|
|
|
- finish();
|
|
|
+
|
|
|
} else {
|
|
|
- startTimeoutTimer();
|
|
|
JCCallItem item = mVideoManager.getActiveCall();
|
|
|
if (item == null) {
|
|
|
return;
|
|
@@ -141,37 +158,40 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
int state = activeItem.getState();
|
|
|
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) {
|
|
|
- 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;
|
|
|
- }
|
|
|
+ updateLayout_pending(item);
|
|
|
} else if (state == JCCall.STATE_CONNECTING) {
|
|
|
mHintText.setText(R.string.connecting);
|
|
|
} else if (state == JCCall.STATE_TALKING) {
|
|
|
+ updateLayout_talking(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateLayout_pending(JCCallItem item) {
|
|
|
+ if (mLocalCanvas == null && item.getUploadVideoStreamSelf()) {
|
|
|
+ mLocalCanvas = mVideoManager.mMediaDevice.startCameraVideo(JCMediaDevice.RENDER_FULL_SCREEN);
|
|
|
+ startTimeoutTimer();
|
|
|
if (mLocalCanvas != null) {
|
|
|
- mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
- mLocalCanvas = null;
|
|
|
+ mLocalCanvas.getVideoView().setZOrderMediaOverlay(true);
|
|
|
+ mLocalCanvas.getVideoView().setId(View.generateViewId());
|
|
|
+ mVideoLayout.addView(mLocalCanvas.getVideoView(), 0);
|
|
|
}
|
|
|
- if (mRemoteCanvas == null && item.getUploadVideoStreamOther()) {
|
|
|
- startTalkingTimer();
|
|
|
- mVideoManager.mMediaDevice.enableSpeaker(true);
|
|
|
- mRemoteCanvas = mVideoManager.mMediaDevice.startVideo(item.getRenderId(), JCMediaDevice.RENDER_FULL_CONTENT);
|
|
|
- if (mRemoteCanvas != null) {
|
|
|
- mRemoteCanvas.getVideoView().setId(View.generateViewId());
|
|
|
- mVideoLayout.addView(mRemoteCanvas.getVideoView(), 0);
|
|
|
- }
|
|
|
- } else if (mRemoteCanvas != null && !item.getUploadVideoStreamOther()) {
|
|
|
- mVideoManager.mMediaDevice.stopVideo(mRemoteCanvas);
|
|
|
- mVideoLayout.removeView(mRemoteCanvas.getVideoView());
|
|
|
- mRemoteCanvas = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateLayout_talking(JCCallItem item) {
|
|
|
+ if (mLocalCanvas != null) {
|
|
|
+ mVideoLayout.removeView(mLocalCanvas.getVideoView());
|
|
|
+ mLocalCanvas = null;
|
|
|
+ }
|
|
|
+ if (mRemoteCanvas == null && item.getUploadVideoStreamOther()) {
|
|
|
+ stopTimeoutTimer();
|
|
|
+ startTalkingTimer();
|
|
|
+ mMediaPlayerUtils.stopSound();
|
|
|
+ mVideoManager.mMediaDevice.enableSpeaker(true);
|
|
|
+ mRemoteCanvas = mVideoManager.mMediaDevice.startVideo(item.getRenderId(), JCMediaDevice.RENDER_FULL_CONTENT);
|
|
|
+ if (mRemoteCanvas != null) {
|
|
|
+ mRemoteCanvas.getVideoView().setId(View.generateViewId());
|
|
|
+ mVideoLayout.addView(mRemoteCanvas.getVideoView(), 0);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -191,31 +211,13 @@ 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);
|
|
|
- int width = wm.getDefaultDisplay().getWidth();
|
|
|
- int height = wm.getDefaultDisplay().getHeight();
|
|
|
- int viewwidth = ToolsUtils.dip2px(this, 128f);
|
|
|
- int viewheight = ToolsUtils.dip2px(this, 184f);
|
|
|
- if (rawX < viewwidth / 2) {
|
|
|
- rawX = (float)(viewwidth / 2 + 8);
|
|
|
- }
|
|
|
- if (rawY < viewheight / 2) {
|
|
|
- rawY = (float)(viewwidth / 2 + 24);
|
|
|
- }
|
|
|
- if (rawX > width - viewwidth / 2) {
|
|
|
- rawX = (float)(width - viewwidth / 2);
|
|
|
- }
|
|
|
- if (rawY > height - viewheight / 2) {
|
|
|
- rawY = (float)(height - viewheight / 2);
|
|
|
- }
|
|
|
- params.leftMargin = (int)(rawX - viewwidth / 2);
|
|
|
- params.topMargin = (int)(rawY - viewheight / 2);
|
|
|
- view.setLayoutParams(params);
|
|
|
+ mMediaPlayerUtils.playSound(this, R.raw.video_cancel, false);
|
|
|
+ new Handler().postDelayed(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }, 2000);
|
|
|
}
|
|
|
|
|
|
/*动态申请权限*/
|
|
@@ -229,25 +231,8 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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() {
|
|
|
+ Log.d(TAG, "startTimeoutTimer: ");
|
|
|
if (mTimeoutTimer != null) {
|
|
|
stopTimeoutTimer();
|
|
|
}
|
|
@@ -255,12 +240,14 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
mTimeoutTimer.schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
-
|
|
|
+ stopTimeoutTimer();
|
|
|
+ onTimeoutTimerCallback();
|
|
|
}
|
|
|
- }, 1000 );
|
|
|
+ }, 1000*60);
|
|
|
}
|
|
|
|
|
|
private void stopTimeoutTimer() {
|
|
|
+ Log.d(TAG, "stopTimeoutTimer: ");
|
|
|
if (mTimeoutTimer != null) {
|
|
|
mTimeoutTimer.cancel();
|
|
|
mTimeoutTimer = null;
|
|
@@ -268,38 +255,62 @@ public class MainActivity extends Activity implements Listener.VideoListener {
|
|
|
}
|
|
|
|
|
|
private void startTalkingTimer() {
|
|
|
+ Log.d(TAG, "startTalkingTimer: ");
|
|
|
if (mTalkingTimer != null) {
|
|
|
stopTalkingTimer();
|
|
|
}
|
|
|
+ mTimeCount = 0;
|
|
|
mTalkingTimer = new Timer();
|
|
|
mTalkingTimer.schedule(new TimerTask() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
- refreshTimeLabel();
|
|
|
+ onTalkingTiemrCallback();
|
|
|
}
|
|
|
- }, 1000);
|
|
|
+ }, 1000, 1000);
|
|
|
}
|
|
|
|
|
|
private void stopTalkingTimer() {
|
|
|
+ Log.d(TAG, "stopTalkingTimer: ");
|
|
|
if (mTalkingTimer != null) {
|
|
|
mTalkingTimer.cancel();
|
|
|
mTalkingTimer = null;
|
|
|
}
|
|
|
+ mTimeCount = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void onTimeoutTimerCallback() {
|
|
|
+ showToast(getString(R.string.timeout));
|
|
|
+ mVideoManager.hangup();
|
|
|
}
|
|
|
|
|
|
@SuppressLint("DefaultLocale")
|
|
|
- private void refreshTimeLabel() {
|
|
|
- long hours = mTimeCount / 3600;
|
|
|
- mTimeCount %= 3600;
|
|
|
- long minutes = mTimeCount / 60;
|
|
|
- long second = mTimeCount %= 60;
|
|
|
+ private void onTalkingTiemrCallback() {
|
|
|
+ mTimeCount ++;
|
|
|
+ Log.d(TAG, "onTalkingTiemrCallback: " + mTimeCount);
|
|
|
+
|
|
|
+ int count = mTimeCount;
|
|
|
+ long hours = count / 3600;
|
|
|
+ count %= 3600;
|
|
|
+ long minutes = count / 60;
|
|
|
+ long second = count %= 60;
|
|
|
String text = hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, second) : String.format("%02d:%02d", minutes, second);
|
|
|
- mHintText.setText(text);
|
|
|
+ Log.d(TAG, "onTalkingTiemrCallback: text:" + text);
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mHintText.setText(text);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- private void toast(String content) {
|
|
|
- Toast t = Toast.makeText(this, content, Toast.LENGTH_SHORT);
|
|
|
- t.show();
|
|
|
+ private void showToast(String content) {
|
|
|
+ runOnUiThread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ Toast t = Toast.makeText(getApplicationContext(), content, Toast.LENGTH_SHORT);
|
|
|
+ t.show();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Override
|