完成屏幕分享流显示处理

This commit is contained in:
zher52 2022-02-17 19:37:18 +08:00
parent fb422155cc
commit e1cf74bb39
7 changed files with 165 additions and 73 deletions

View File

@ -9,7 +9,6 @@
<dependency id="cordova-plugin-androidx"/>
<dependency id="cordova-plugin-androidx-adapter"/>
<preference name="APP_ID" default="sdk_app_id"/>
<preference name="PERMISSION_MIC_DESC" default="应用需要访问您的麦克风"/>
<preference name="PERMISSION_CAMERA_DESC" default="应用需要访问您的摄像头"/>
@ -21,23 +20,24 @@
<clobbers target="cordova.plugin.trtc"/>
</js-module>
<!-- <platform name="ios">-->
<!-- <config-file target="config.xml" parent="/*">-->
<!-- <feature name="Trtc">-->
<!-- <param name="ios-package" value="TrtcPlugin"/>-->
<!-- &lt;!&ndash; <param name="onload" value="true" /> &ndash;&gt;-->
<!-- </feature>-->
<!-- </config-file>-->
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="Trtc">
<param name="ios-package" value="TrtcPlugin"/>
<!-- <param name="onload" value="true" /> -->
</feature>
</config-file>
<!-- <config-file target="*-Info.plist" parent="NSMicrophoneUsageDescription">-->
<!-- <string>$PERMISSION_MIC_DESC</string>-->
<!-- </config-file>-->
<!-- <config-file target="*-Info.plist" parent="NSCameraUsageDescription">-->
<!-- <string>$PERMISSION_CAMERA_DESC</string>-->
<!-- </config-file>-->
<config-file target="*-Info.plist" parent="NSMicrophoneUsageDescription">
<string>$PERMISSION_MIC_DESC</string>
</config-file>
<config-file target="*-Info.plist" parent="NSCameraUsageDescription">
<string>$PERMISSION_CAMERA_DESC</string>
</config-file>
<header-file src="src/ios/TrtcPlugin.h"/>
<source-file src="src/ios/TrtcPlugin.m"/>
<!-- <header-file src="src/ios/TrtcPlugin.h"/>-->
<!-- <source-file src="src/ios/TrtcPlugin.m"/>-->
<!-- <header-file src="src/ios/Trtc/TCLiveConfigDefine.h"/>-->
<!-- <header-file src="src/ios/Trtc/TCLiveJoinRoomViewController.h"/>-->
<!-- <source-file src="src/ios/Trtc/TCLiveJoinRoomViewController.m"/>-->
@ -134,7 +134,7 @@
<!-- <config-file target="*TrtcConfig.plist" parent="AppId">-->
<!-- <string>$APP_ID</string>-->
<!-- </config-file>-->
<!-- </platform>-->
</platform>
<platform name="android">
<config-file target="config.xml" parent="/*">
@ -157,33 +157,8 @@
<!-- <uses-feature android:name="android.hardware.camera.autofocus" />-->
</config-file>
<config-file target="res/values/strings.xml" parent="/resources">
<!-- <string name="trtc_app_id">$APP_ID</string>-->
<!-- <string name="str_enter_tips">腾讯视频通话</string>-->
<!-- <string name="str_room_title">房间名</string>-->
<!-- <string name="str_room_id">房间ID</string>-->
<!-- <string name="str_create_btn">创建房间</string>-->
<!-- <string name="str_switch_camera">翻转</string>-->
<!-- <string name="str_chat_tab">聊天</string>-->
<!-- <string name="str_wb_tab">白板</string>-->
<!-- <string name="msg_title">消息</string>-->
<!-- <string name="str_input_tips">输入文字内容</string>-->
<!-- <string name="str_beauty">美颜</string>-->
<!-- <string name="str_log">日志</string>-->
<!-- <string name="str_voice">声音</string>-->
<!-- <string name="str_room_id_tips">输入房间号</string>-->
<!-- <string name="str_enter_room_btn">进入房间</string>-->
<!-- <string name="str_role">配置</string>-->
<!-- <string name="str_feedback">反馈</string>-->
<!-- <string name="str_set_role">请选择要配置的分辨率</string>-->
<!-- <string name="str_chat">聊天</string>-->
<!-- <string name="str_set_problem">请选择反馈类型</string>-->
<!-- <string name="str_problem_other">请输入具体问题描述</string>-->
<!-- <string name="str_feedback_ret">非常感谢您的反馈</string>-->
<!-- <string name="str_login_success">登录成功</string>-->
<string name="common_please_input_roomid_and_userid">用户没有允许需要的权限,加入通话失败</string>
<config-file target="res/values/strings.xml" parent="/resources">
<string name="common_please_input_roomid_and_userid">用户没有允许需要的权限,加入通话失败</string>
<string name="main_trtc_base_funciton">基础功能</string>
<string name="main_item_aduio_call">语音通话</string>
<string name="main_item_aduio_call_desc">双人/多人语音通话、包含静音/免提等功能</string>
@ -282,11 +257,9 @@
<resource-file src="src/android/res/mipmap-xxhdpi/swap_camera.png" target="res/mipmap-xxhdpi/swap_camera.png"/>
<resource-file src="src/android/res/mipmap-xxhdpi/view_close.png" target="res/mipmap-xxhdpi/view_close.png"/>
<resource-file src="src/android/res/mipmap-xxhdpi/view_open.png" target="res/mipmap-xxhdpi/view_open.png"/>
<resource-file src="src/android/res/mipmap-xxhdpi/rotation.png" target="res/mipmap-xxhdpi/rotation.png"/>
<!-- <lib-file src="src/android/libs/lib.jar" /> -->
<framework src="com.tencent.liteav:LiteAVSDK_TRTC:latest.release"/>
<framework src="androidx.appcompat:appcompat:1.1.0"/>
<framework src="androidx.constraintlayout:constraintlayout:1.1.3"/>

View File

@ -1,7 +1,9 @@
package com.tencent.trtc;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
@ -13,6 +15,8 @@ import com.tencent.trtc.videocall.UserInfo;
public class CustomVideoView extends RelativeLayout {
private static final String TAG = "CustomVideoView";
private Context mContext;
private View mView;
@ -24,6 +28,8 @@ public class CustomVideoView extends RelativeLayout {
private boolean alwaysHide = false;
private boolean mainView;
private TRTCCloud mTRTCCloud;
public CustomVideoView(Context context) {
this(context,null);
@ -55,29 +61,46 @@ public class CustomVideoView extends RelativeLayout {
return getResources().getIdentifier(idName, type, mContext.getPackageName());
}
public void changeUser(TRTCCloud mTRTCCloud, UserInfo userInfo) {
public void changeUser(UserInfo userInfo) {
if(this.mTRTCCloud == null){
this.mTRTCCloud = TRTCCloud.sharedInstance(mContext);
}
Log.d(TAG,"TRTC - changeUser: main?:"+mainView+",alwaysHide?:"+alwaysHide+",user:" + (userInfo == null ? null : userInfo.getPersonid()));
this.setBackgroundColor(Color.TRANSPARENT);
if(userInfo == null){
setVisibility(View.GONE);
setVisibility(View.GONE);;
}else {
setVisibility(alwaysHide?INVISIBLE:VISIBLE);
}
if(isChanged(userInfo)){
this.titleView.setVisibility(INVISIBLE);
this.userInfo = userInfo;
if(this.userInfo != null){
TRTCCloudDef.TRTCRenderParams params = new TRTCCloudDef.TRTCRenderParams();
params.rotation = 0;
params.fillMode = this.userInfo.isShareUser() ? TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FIT : TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FILL;
if(this.userInfo.isLocal()){
mTRTCCloud.startLocalPreview(userInfo.isFrontCamera(), videoView);
mTRTCCloud.startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_SPEECH);
mTRTCCloud.setLocalRenderParams(params);
} else {
mTRTCCloud.startRemoteView(this.userInfo.getPersonid(), TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL, videoView);
mTRTCCloud.startRemoteView(this.userInfo.getPersonid(), mainView ? TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG : TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL, videoView);
mTRTCCloud.setRemoteRenderParams(this.userInfo.getPersonid(),mainView ? TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG : TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB,params);
}
if(this.userInfo.getDisplayName() == null || this.userInfo.getDisplayName().length() == 0){
this.titleView.setText(this.userInfo.getPersonid());
this.titleView.setText(this.userInfo.getPersonid() + (this.userInfo.isShareUser() ? "的屏幕分享": ""));
}else {
this.titleView.setText(this.userInfo.getDisplayName());
this.titleView.setText(this.userInfo.getDisplayName() + (this.userInfo.isShareUser() ? "的屏幕分享": ""));
}
if(this.userInfo.isLocal()){
this.titleView.setText("");
}
this.titleView.setVisibility(VISIBLE);
}else {
this.titleView.setVisibility(INVISIBLE);
if(!alwaysHide){
if(!mainView){
this.setBackgroundColor(Color.BLACK);
}
}
}
}
}
@ -101,17 +124,37 @@ public class CustomVideoView extends RelativeLayout {
}
public CustomVideoView setMainView(boolean mainView) {
if(this.mTRTCCloud == null){
this.mTRTCCloud = TRTCCloud.sharedInstance(mContext);
}
this.mainView = mainView;
if(!mainView){
Events.addListener("subview.always.hide",(extra)->{
this.alwaysHide = extra.getBoolean("alwaysHide",false);
this.setVisibility(alwaysHide?INVISIBLE:VISIBLE);
if(this.alwaysHide){
this.setVisibility(INVISIBLE);
if(this.getUserInfo() != null){
if(!this.getUserInfo().isLocal()){
mTRTCCloud.stopRemoteView(this.getUserInfo().getPersonid(),TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB);
}
}
} else {
if(this.getUserInfo() != null){
this.setVisibility(VISIBLE);
if(!this.getUserInfo().isLocal()){
mTRTCCloud.startRemoteView(
this.getUserInfo().getPersonid(),
this.mainView ? TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG : TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SMALL,
getVideoView());
}
}
}
});
}
Events.addListener("userinfo.update",(extra) -> {
if(this.userInfo !=null && extra.getString("userId").equals(this.userInfo.getPersonid())){
if(this.userInfo !=null && !this.userInfo.isLocal() && extra.getString("userId").equals(this.userInfo.getPersonid())){
this.userInfo.setDisplayName(extra.getString("displayName"));
this.titleView.setText(extra.getString("displayName",this.userInfo.getDisplayName()));
this.titleView.setText(this.userInfo.getDisplayName() + (this.userInfo.isShareUser() ? "的屏幕分享": ""));
}
});
return this;
@ -120,4 +163,8 @@ public class CustomVideoView extends RelativeLayout {
public UserInfo getUserInfo() {
return userInfo;
}
public TXCloudVideoView getVideoView() {
return videoView;
}
}

View File

@ -5,7 +5,8 @@ import androidx.annotation.Nullable;
public class UserInfo {
String personid;
String displayName;
boolean isLocal;
boolean local;
boolean frontCamera = true;
@ -19,7 +20,7 @@ public class UserInfo {
}
public String getDisplayName() {
return displayName;
return displayName;
}
public UserInfo setDisplayName(String displayName) {
@ -28,11 +29,11 @@ public class UserInfo {
}
public boolean isLocal() {
return isLocal;
return local;
}
public UserInfo setLocal(boolean local) {
isLocal = local;
this.local = local;
return this;
}
@ -45,6 +46,9 @@ public class UserInfo {
return this;
}
public boolean isShareUser() {
return personid != null && personid.startsWith("share_");
}
@Override
public int hashCode() {

View File

@ -64,6 +64,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
// private CustomVideoView mTXCVVLocalPreviewView;
private ImageView mImageBack;
private ImageView mButtonMuteVideo;
private ImageView mButtonRotation;
private ImageView mButtonMuteAudio;
private ImageView mButtonSwitchCamera;
private ImageView mButtonAudioRoute;
@ -81,8 +82,13 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
private boolean hideSub;
private boolean mAudioRouteFlag = true;
private int rotation = 0;
private boolean mButtonMuteVideoButtonStatusBackup;
private UserInfo localUserInfo;
private UserInfo shareUserInfo;
private int getId(String idName, String type) {
return getResources().getIdentifier(idName, type, getPackageName());
}
@ -131,6 +137,8 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
// R.id.txcvv_main
// R.id.btn_mute_video
mButtonMuteVideo = findViewById(getId("btn_mute_video", "id"));
mButtonRotation = findViewById(getId("btn_rotation","id"));
// R.id.btn_mute_audio
mButtonMuteAudio = findViewById(getId("btn_mute_audio", "id"));
// R.id.btn_switch_camera
@ -143,6 +151,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
}
mImageBack.setOnClickListener(this);
mButtonMuteVideo.setOnClickListener(this);
mButtonRotation.setOnClickListener(this);
mButtonMuteAudio.setOnClickListener(this);
mButtonSwitchCamera.setOnClickListener(this);
mButtonAudioRoute.setOnClickListener(this);
@ -156,14 +165,16 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
CustomVideoView videoView = ((CustomVideoView) findViewById(getId("trtc_view_"+i, "id"))).setMainView(i == 0);
if(i > 0){
videoView.setOnClickListener((view)->{
if(view instanceof CustomVideoView && !((CustomVideoView) view).isMainView()){
if(view instanceof CustomVideoView && !((CustomVideoView) view).isMainView() && ((CustomVideoView) view).getUserInfo() != null){
UserInfo mainUser = this.mUserList.get(0);
UserInfo viewUser = ((CustomVideoView) view).getUserInfo();
Collections.swap(this.mUserList,0,this.mUserList.indexOf(viewUser));
mTRTCCloud.stopLocalPreview();
mTRTCCloud.stopLocalAudio();
mRemoteViewList.get(0).changeUser(mTRTCCloud,viewUser);
((CustomVideoView) view).changeUser(mTRTCCloud,mainUser);
if(mainUser.isLocal() || viewUser.isLocal()){
mTRTCCloud.stopLocalPreview();
mTRTCCloud.stopLocalAudio();
}
mRemoteViewList.get(0).changeUser(viewUser);
((CustomVideoView) view).changeUser(mainUser);
try {
JSONObject object = new JSONObject();
object.put("room",mRoomId);
@ -199,7 +210,7 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
trtcParams.roomId = Integer.parseInt(mRoomId);
trtcParams.userSig = this.userSig;
mRemoteViewList.get(0).changeUser(mTRTCCloud, mUserList.get(0));
mRemoteViewList.get(0).changeUser(mUserList.get(0));
mTRTCCloud.enterRoom(trtcParams, TRTCCloudDef.TRTC_APP_SCENE_VIDEOCALL);
}
@ -249,6 +260,8 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
switchCamera();
} else if (id == getId("btn_audio_route", "id")) {
audioRoute();
} else if (id == getId("btn_rotation", "id")) {
rotation();
}
}
@ -264,6 +277,34 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
mButtonMuteVideo.setSelected(!isSelected);
}
private void rotation(){
TRTCCloudDef.TRTCRenderParams params = new TRTCCloudDef.TRTCRenderParams();
params.fillMode = TRTCCloudDef.TRTC_VIDEO_RENDER_MODE_FIT;
rotation += 90;
rotation = rotation > 270 ? 0: rotation;
params.rotation = rotation;
mTRTCCloud.setRemoteRenderParams(mUserList.get(0).getPersonid(),TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_BIG ,params);
}
private void disableMuteVideo(){
boolean isSelected = mButtonMuteVideo.isSelected();
mButtonMuteVideoButtonStatusBackup = isSelected;
if (!isSelected) {
Events.fireEvent("subview.always.hide",(extra)->extra.putBoolean("alwaysHide",!isSelected));
}
mButtonMuteVideo.setVisibility(View.GONE);
mButtonRotation.setVisibility(View.VISIBLE);
}
private void enableMuteVideo(){
mButtonMuteVideo.setVisibility(View.VISIBLE);
mButtonRotation.setVisibility(View.GONE);
if(!mButtonMuteVideoButtonStatusBackup){
Events.fireEvent("subview.always.hide",(extra)->extra.putBoolean("alwaysHide",mButtonMuteVideoButtonStatusBackup));
}
rotation = 0;
}
private void muteAudio() {
boolean isSelected = mButtonMuteAudio.isSelected();
if (!isSelected) {
@ -313,13 +354,25 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
if (index != -1) {
return;
}
mUserList.add(info);
if(info.isShareUser()){
shareUserInfo = info;
mUserList.add(0,info);
mTRTCCloud.stopLocalPreview();
mTRTCCloud.stopLocalAudio();
} else {
mUserList.add(info);
}
refreshRemoteVideoViews();
} else {
if (index == -1) {
return;
}
mTRTCCloud.stopRemoteView(userId);
if(info.isShareUser()){
shareUserInfo = null;
mTRTCCloud.stopLocalPreview();
mTRTCCloud.stopLocalAudio();
}
mTRTCCloud.stopRemoteView(userId,TRTCCloudDef.TRTC_VIDEO_STREAM_TYPE_SUB);
mUserList.remove(index);
refreshRemoteVideoViews();
}
@ -340,11 +393,16 @@ public class VideoCallingActivity extends TRTCBaseActivity implements View.OnCli
for (int i = 0; i < mRemoteViewList.size(); i++) {
if (i < mUserList.size()) {
UserInfo user = mUserList.get(i);
mRemoteViewList.get(i).changeUser(mTRTCCloud,user);
mRemoteViewList.get(i).changeUser(user);
} else {
mRemoteViewList.get(i).changeUser(mTRTCCloud,null);
mRemoteViewList.get(i).changeUser(null);
}
}
if(shareUserInfo != null){
disableMuteVideo();
} else {
enableMuteVideo();
}
}

View File

@ -1,12 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
>
<com.tencent.rtmp.ui.TXCloudVideoView
android:id="@+id/video"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"

View File

@ -142,6 +142,13 @@
android:layout_height="20dp"
android:src="@mipmap/view_close"
android:layout_weight="1" />
<ImageView
android:id="@+id/btn_rotation"
android:layout_width="40dp"
android:layout_height="20dp"
android:src="@mipmap/rotation"
android:visibility="gone"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB