|
@@ -1,18 +1,11 @@
|
|
|
package com.tencent.trtc.videocall;
|
|
package com.tencent.trtc.videocall;
|
|
|
|
|
|
|
|
-import static android.widget.RelativeLayout.ALIGN_PARENT_END;
|
|
|
|
|
|
|
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
-import android.net.Uri;
|
|
|
|
|
-import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
-import android.provider.Settings;
|
|
|
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
-import android.view.ViewGroup;
|
|
|
|
|
-import android.widget.Button;
|
|
|
|
|
-import android.widget.ImageView;
|
|
|
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
import android.widget.Toast;
|
|
@@ -24,38 +17,17 @@ import com.tencent.trtc.TRTCCloud;
|
|
|
import com.tencent.trtc.TRTCCloudDef;
|
|
import com.tencent.trtc.TRTCCloudDef;
|
|
|
import com.tencent.trtc.TRTCCloudListener;
|
|
import com.tencent.trtc.TRTCCloudListener;
|
|
|
|
|
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
|
|
+import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
+import org.json.JSONException;
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
+
|
|
|
import java.lang.ref.WeakReference;
|
|
import java.lang.ref.WeakReference;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * TRTC视频通话的主页面
|
|
|
|
|
- * <p>
|
|
|
|
|
- * 包含如下简单功能:
|
|
|
|
|
- * - 进入视频通话房间{@link VideoCallingActivity#enterRoom()}
|
|
|
|
|
- * - 退出视频通话房间{@link VideoCallingActivity#exitRoom()}
|
|
|
|
|
- * - 切换前置/后置摄像头{@link VideoCallingActivity#switchCamera()}
|
|
|
|
|
- * - 打开/关闭摄像头{@link VideoCallingActivity#muteVideo()}
|
|
|
|
|
- * - 打开/关闭麦克风{@link VideoCallingActivity#muteAudio()}
|
|
|
|
|
- * - 显示房间内其他用户的视频画面(当前示例最多可显示6个其他用户的视频画面){@link TRTCCloudImplListener#refreshRemoteVideoViews()}
|
|
|
|
|
- * <p>
|
|
|
|
|
- * - 详见接入文档{https://cloud.tencent.com/document/product/647/42045}
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
-/**
|
|
|
|
|
- * Video Call
|
|
|
|
|
- * <p>
|
|
|
|
|
- * Features:
|
|
|
|
|
- * - Enter a video call room: {@link VideoCallingActivity#enterRoom()}
|
|
|
|
|
- * - Exit a video call room: {@link VideoCallingActivity#exitRoom()}
|
|
|
|
|
- * - Display the video of other users (max. 6) in the room: {@link TRTCCloudImplListener#refreshRemoteVideoViews()}
|
|
|
|
|
- * <p>
|
|
|
|
|
- * - For more information, please see the integration document {https://cloud.tencent.com/document/product/647/42045}.
|
|
|
|
|
- */
|
|
|
|
|
|
|
+
|
|
|
public class VideoCallingActivity extends TRTCBaseActivity implements View.OnClickListener {
|
|
public class VideoCallingActivity extends TRTCBaseActivity implements View.OnClickListener {
|
|
|
|
|
|
|
|
private static final String TAG = "VideoCallingActivity";
|
|
private static final String TAG = "VideoCallingActivity";
|
|
|
- private static final int OVERLAY_PERMISSION_REQ_CODE = 1234;
|
|
|
|
|
|
|
|
|
|
private TXCloudVideoView mTXCVVLocalPreviewView;
|
|
private TXCloudVideoView mTXCVVLocalPreviewView;
|
|
|
private TXCloudVideoView mTXCVVLocalTwoView;
|
|
private TXCloudVideoView mTXCVVLocalTwoView;
|
|
@@ -63,7 +35,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
private RelativeLayout rl_maike;
|
|
private RelativeLayout rl_maike;
|
|
|
private RelativeLayout rl_guaduan;
|
|
private RelativeLayout rl_guaduan;
|
|
|
private RelativeLayout rl_qiehuan;
|
|
private RelativeLayout rl_qiehuan;
|
|
|
-
|
|
|
|
|
|
|
+private TextView tv_yuyin;
|
|
|
private TRTCCloud mTRTCCloud;
|
|
private TRTCCloud mTRTCCloud;
|
|
|
private TXDeviceManager mTXDeviceManager;
|
|
private TXDeviceManager mTXDeviceManager;
|
|
|
private boolean mIsFrontCamera = true;
|
|
private boolean mIsFrontCamera = true;
|
|
@@ -73,11 +45,17 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
private String mUserId;
|
|
private String mUserId;
|
|
|
private boolean mAudioRouteFlag = true;
|
|
private boolean mAudioRouteFlag = true;
|
|
|
private boolean mVideoViewFlag = true;
|
|
private boolean mVideoViewFlag = true;
|
|
|
|
|
+ private String streamId;
|
|
|
|
|
+ private String userSig;
|
|
|
|
|
+ private String sdkAppId;
|
|
|
|
|
+ private String privateMapKey;
|
|
|
|
|
+ private String mIsVideo;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.videocall_activity_calling);
|
|
setContentView(R.layout.videocall_activity_calling);
|
|
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
handleIntent();
|
|
handleIntent();
|
|
|
|
|
|
|
|
if (checkPermission()) {
|
|
if (checkPermission()) {
|
|
@@ -92,9 +70,24 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
if (intent.getStringExtra(Constant.USER_ID) != null) {
|
|
if (intent.getStringExtra(Constant.USER_ID) != null) {
|
|
|
mUserId = intent.getStringExtra(Constant.USER_ID);
|
|
mUserId = intent.getStringExtra(Constant.USER_ID);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (intent.getStringExtra(Constant.STREAM_ID) != null) {
|
|
|
|
|
+ streamId = intent.getStringExtra(Constant.STREAM_ID);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (intent.getStringExtra(Constant.USER_SIG) != null) {
|
|
|
|
|
+ userSig = intent.getStringExtra(Constant.USER_SIG);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (intent.getStringExtra(Constant.SDK_APP_ID) != null) {
|
|
|
|
|
+ sdkAppId = intent.getStringExtra(Constant.SDK_APP_ID);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (intent.getStringExtra(Constant.PRIVATE_MAP_KEY) != null) {
|
|
|
|
|
+ privateMapKey = intent.getStringExtra(Constant.PRIVATE_MAP_KEY);
|
|
|
|
|
+ }
|
|
|
if (intent.getStringExtra(Constant.ROOM_ID) != null) {
|
|
if (intent.getStringExtra(Constant.ROOM_ID) != null) {
|
|
|
mRoomId = intent.getStringExtra(Constant.ROOM_ID);
|
|
mRoomId = intent.getStringExtra(Constant.ROOM_ID);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (intent.getStringExtra(Constant.IS_VIDEO) != null) {
|
|
|
|
|
+ mIsVideo = intent.getStringExtra(Constant.IS_VIDEO);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -105,6 +98,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
rl_maike = findViewById(R.id.rl_maike);
|
|
rl_maike = findViewById(R.id.rl_maike);
|
|
|
rl_guaduan = findViewById(R.id.rl_guaduan);
|
|
rl_guaduan = findViewById(R.id.rl_guaduan);
|
|
|
rl_qiehuan = findViewById(R.id.rl_qiehuan);
|
|
rl_qiehuan = findViewById(R.id.rl_qiehuan);
|
|
|
|
|
+ tv_yuyin = findViewById(R.id.tv_yuyin);
|
|
|
rl_maike.setOnClickListener(this);
|
|
rl_maike.setOnClickListener(this);
|
|
|
rl_guaduan.setOnClickListener(this);
|
|
rl_guaduan.setOnClickListener(this);
|
|
|
rl_qiehuan.setOnClickListener(this);
|
|
rl_qiehuan.setOnClickListener(this);
|
|
@@ -116,14 +110,21 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
mTXDeviceManager = mTRTCCloud.getDeviceManager();
|
|
mTXDeviceManager = mTRTCCloud.getDeviceManager();
|
|
|
|
|
|
|
|
TRTCCloudDef.TRTCParams trtcParams = new TRTCCloudDef.TRTCParams();
|
|
TRTCCloudDef.TRTCParams trtcParams = new TRTCCloudDef.TRTCParams();
|
|
|
- trtcParams.sdkAppId = GenerateTestUserSig.SDKAPPID;
|
|
|
|
|
|
|
+ trtcParams.sdkAppId = Integer.parseInt(sdkAppId);
|
|
|
trtcParams.userId = mUserId;
|
|
trtcParams.userId = mUserId;
|
|
|
- trtcParams.roomId = Integer.parseInt(mRoomId);
|
|
|
|
|
- trtcParams.userSig = GenerateTestUserSig.genTestUserSig(trtcParams.userId);
|
|
|
|
|
|
|
+ trtcParams.strRoomId = mRoomId;
|
|
|
|
|
+ trtcParams.userSig = userSig;
|
|
|
|
|
+ trtcParams.privateMapKey=privateMapKey;
|
|
|
|
|
|
|
|
- mTRTCCloud.startLocalPreview(mIsFrontCamera, mTXCVVLocalPreviewView);
|
|
|
|
|
|
|
+ if (mIsVideo.equals("true")) {
|
|
|
|
|
+ mTRTCCloud.startLocalPreview(mIsFrontCamera, mTXCVVLocalPreviewView);
|
|
|
|
|
+ tv_yuyin.setVisibility(View.GONE);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ tv_yuyin.setVisibility(View.VISIBLE);
|
|
|
|
|
+ }
|
|
|
mTRTCCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH);
|
|
mTRTCCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH);
|
|
|
mTRTCCloud.enterRoom(trtcParams, TRTCCloudDef.TRTC_APP_SCENE_VIDEOCALL);
|
|
mTRTCCloud.enterRoom(trtcParams, TRTCCloudDef.TRTC_APP_SCENE_VIDEOCALL);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -131,9 +132,17 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
super.onStop();
|
|
super.onStop();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
|
|
+ public void stopTrtcasEvent(TrtcEventT trtcEvent) {
|
|
|
|
|
+ if (1 == trtcEvent.getCode() && "FUSHAN_TRTC_STOP".equals(trtcEvent.getTrtcType())) {
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
exitRoom();
|
|
exitRoom();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -169,6 +178,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
} else if (id == R.id.rl_maike) {
|
|
} else if (id == R.id.rl_maike) {
|
|
|
muteAudio();
|
|
muteAudio();
|
|
|
} else if (id == R.id.rl_guaduan) {
|
|
} else if (id == R.id.rl_guaduan) {
|
|
|
|
|
+ EventBus.getDefault().post(new TrtcEvent(2, "FUSHAN_TRTC_STOP"));
|
|
|
finish();
|
|
finish();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -214,6 +224,14 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
mContext = new WeakReference<>(activity);
|
|
mContext = new WeakReference<>(activity);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onEnterRoom(long result) {
|
|
|
|
|
+ super.onEnterRoom(result);
|
|
|
|
|
+ if(result>0){
|
|
|
|
|
+// mTRTCCloud.startPublishing(streamId, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void onUserVideoAvailable(String userId, boolean available) {
|
|
public void onUserVideoAvailable(String userId, boolean available) {
|
|
|
Log.d(TAG, "onUserVideoAvailable userId " + userId + ", mUserCount " + mUserCount + ",available " + available);
|
|
Log.d(TAG, "onUserVideoAvailable userId " + userId + ", mUserCount " + mUserCount + ",available " + available);
|
|
@@ -231,7 +249,9 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void refreshRemoteVideoViews() {
|
|
private void refreshRemoteVideoViews() {
|
|
|
- mTRTCCloud.startRemoteView(mRemoteUid, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL, mTXCVVLocalTwoView);
|
|
|
|
|
|
|
+ if (mIsVideo.equals("true")) {
|
|
|
|
|
+ mTRTCCloud.startRemoteView(mRemoteUid, TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL, mTXCVVLocalTwoView);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|