视频优化1

This commit is contained in:
fuenmao 2024-12-09 15:22:34 +08:00
parent 699a1f25ed
commit ed9e68e73a
3 changed files with 273 additions and 64 deletions

View File

@ -193,37 +193,27 @@ class MeetingMainLogic extends GetxController with RequestToolMixin{
Future<void> doHttpGetTvAnchor() async { Future<void> doHttpGetTvAnchor() async {
BaseStructureResult res = await getClient().getTvAnchor(state.roomNumber.value); BaseStructureResult res = await getClient().getTvAnchor(state.roomNumber.value);
state.remoteUid.value = res.data!.toString(); state.remoteUid.value = res.data!.toString();
MeetingRoomUser? temporaryMru;
for(MeetingRoomUser mru in state.cacheUsers.value){
if(mru.uid == res.data!.toString()){
temporaryMru = mru;
}
}
var isExist = false;
for(MeetingRoomUser mru in state.videoUsers.value){
if(temporaryMru!.uid == mru.uid){
isExist = true;
}
}
if(isExist == false){
state.videoUsers.value.add(temporaryMru!);
}
if(res.data!.toString().length != 9){ if(res.data!.toString().length != 9){
if(state.remoteUid.value != UserStore.to.userInfoEntity.value!.uid) { if(state.remoteUid.value != UserStore.to.userInfoEntity.value!.uid) {
Future.delayed(const Duration(milliseconds: 1000), () { state.isSelf.value = false;
changePageState(1); }else{
}); state.isSelf.value = true;
} }
}else{ }else{
if(state.remoteUid.value != UserStore.to.userInfoEntity.value!.screenShareId){ if(state.remoteUid.value != UserStore.to.userInfoEntity.value!.screenShareId){
Future.delayed(const Duration(milliseconds: 1000), () { if(state.remoteUid.value != UserStore.to.userInfoEntity.value!.uid) {
changePageState(2); state.isSelf.value = false;
}); }else{
state.isSelf.value = true;
}
} }
} }
if(state.isSelf.value == true){
state.floating.value?.close();
}
Future.delayed(const Duration(milliseconds: 1000), () {
changePageState(1);
});
} }
/// ///
@ -307,6 +297,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin{
state.isOpenMicrophone.value = false; state.isOpenMicrophone.value = false;
state.isOpenCamera.value = false; state.isOpenCamera.value = false;
setClientRole("观众"); setClientRole("观众");
changePageState(0);
debugPrint("wgs输出===Socket-关闭发言权限:观众"); debugPrint("wgs输出===Socket-关闭发言权限:观众");
} }
} }
@ -434,25 +425,19 @@ class MeetingMainLogic extends GetxController with RequestToolMixin{
MeetingRoomUser meetingRoomUser = MeetingRoomUser.fromJson(listDynamic); MeetingRoomUser meetingRoomUser = MeetingRoomUser.fromJson(listDynamic);
if(meetingRoomUser.enableCamera == true){ if(meetingRoomUser.enableCamera == true){
debugPrint("wgs输出===Socket-用户单独开摄像头"); debugPrint("wgs输出===Socket-用户单独开摄像头");
for(MeetingRoomUser mru in state.cacheUsers.value){
var isExist = false;
for(MeetingRoomUser mru in state.videoUsers.value){
if(mru.uid == meetingRoomUser.uid){ if(mru.uid == meetingRoomUser.uid){
isExist = true; mru.enableCamera = true;
} }
} }
if(isExist == false){
state.videoUsers.value.add(meetingRoomUser);
}
if(meetingRoomUser.uid == UserStore.to.userInfoEntity.value!.uid){ if(meetingRoomUser.uid == UserStore.to.userInfoEntity.value!.uid){
state.isOpenCamera.value = true; state.isOpenCamera.value = true;
// //
muteLocalVideoStream(false); muteLocalVideoStream(false);
// //
startPreview(); startPreview();
// //
if(state.pageIndex.value == 0){ if(state.pageIndex.value == 0 && state.isSelf.value == false){
// //
state.floating.value?.open(state.context.value!); state.floating.value?.open(state.context.value!);
} }
@ -460,13 +445,11 @@ class MeetingMainLogic extends GetxController with RequestToolMixin{
} }
}else{ }else{
debugPrint("wgs输出===Socket-用户单独闭摄像头"); debugPrint("wgs输出===Socket-用户单独闭摄像头");
for(MeetingRoomUser mru in state.cacheUsers.value){
for(var i = 0; i < state.videoUsers.value.length; i++){ if(mru.uid == meetingRoomUser.uid){
if(state.videoUsers.value[i].uid == meetingRoomUser.uid){ mru.enableCamera = false;
state.videoUsers.value.removeAt(i);
} }
} }
if(meetingRoomUser.uid == UserStore.to.userInfoEntity.value!.uid){ if(meetingRoomUser.uid == UserStore.to.userInfoEntity.value!.uid){
state.isOpenCamera.value = false; state.isOpenCamera.value = false;
@ -476,7 +459,6 @@ class MeetingMainLogic extends GetxController with RequestToolMixin{
stopPreview(); stopPreview();
// //
state.floating.value?.close(); state.floating.value?.close();
state.floating.value?.hideFloating();
} }
} }
}); });

View File

@ -34,7 +34,7 @@ class MeetingMainState {
/// 012 /// 012
late RxInt pageState = 0.obs; late RxInt pageState = 0.obs;
/// pageview指示器 /// pageview指示器
late RxInt pageIndex = 1.obs; late RxInt pageIndex = 0.obs;
/// ///
late RxString roomNumber = "".obs; late RxString roomNumber = "".obs;
@ -56,8 +56,6 @@ class MeetingMainState {
/// ///
late RxList<MeetingRoomUser> cacheUsers = RxList([]); late RxList<MeetingRoomUser> cacheUsers = RxList([]);
late RxList<MeetingRoomUser> videoUsers = RxList([]);
/// ///
late RxBool isSpeak = false.obs; late RxBool isSpeak = false.obs;
/// ///
@ -68,6 +66,8 @@ class MeetingMainState {
late RxBool isOpenCamera = false.obs; late RxBool isOpenCamera = false.obs;
/// ID /// ID
late RxString remoteUid = "".obs; late RxString remoteUid = "".obs;
///
late RxBool isSelf = false.obs;
/// ///
late RxBool isOpenShare = false.obs; late RxBool isOpenShare = false.obs;

View File

@ -87,12 +87,6 @@ class MeetingMainPageState extends State<MeetingMainPage> {
height: 20.h, height: 20.h,
), ),
onTap: () { onTap: () {
if (state.floating.value?.isShowing ==
true) {
state.floating.value?.close();
} else {
state.floating.value?.open(context);
}
}, },
), ),
SizedBox(width: 16.w), SizedBox(width: 16.w),
@ -220,9 +214,9 @@ class MeetingMainPageState extends State<MeetingMainPage> {
child: MeetingMainVoiceComponent( child: MeetingMainVoiceComponent(
users: state.cacheUsers.value)), users: state.cacheUsers.value)),
// // -
Visibility( Visibility(
visible: state.pageState.value == 1, visible: state.pageState.value == 1 && state.isSelf.value == false,
child: null != state.rctEngine.value child: null != state.rctEngine.value
? Stack( ? Stack(
alignment: Alignment.center, alignment: Alignment.center,
@ -230,11 +224,11 @@ class MeetingMainPageState extends State<MeetingMainPage> {
PreloadPageView.builder( PreloadPageView.builder(
preloadPagesCount: 2, preloadPagesCount: 2,
itemCount: 2, itemCount: 2,
itemBuilder: (BuildContext context, int position) => returnPage(position), itemBuilder: (BuildContext context, int position) => returnPageToOther(position),
controller: PreloadPageController(initialPage: 1), controller: PreloadPageController(initialPage: 0),
onPageChanged: (int position) { onPageChanged: (int position) {
state.pageIndex.value = position; state.pageIndex.value = position;
if(state.isSpeak.value == true && state.isOpenCamera.value == true){ if(state.isSpeak.value == true && state.isOpenCamera.value == true && state.isSelf.value == false){
if(position == 0){ if(position == 0){
state.floating.value?.open(context); state.floating.value?.open(context);
}else{ }else{
@ -276,6 +270,55 @@ class MeetingMainPageState extends State<MeetingMainPage> {
) )
: Container()), : Container()),
// -
Visibility(
visible: state.pageState.value == 1 && state.isSelf.value == true,
child: null != state.rctEngine.value
? Stack(
alignment: Alignment.center,
children: [
PreloadPageView.builder(
preloadPagesCount: 2,
itemCount: 2,
itemBuilder: (BuildContext context, int position) => returnPageSelf(position),
controller: PreloadPageController(initialPage: 0),
onPageChanged: (int position) {
state.pageIndex.value = position;
},
),
/// pageview
Positioned(
bottom: 16,
child: Row(
children: [
Container(
width: 8.w,
height: 8.h,
margin: const EdgeInsets.only(right: 6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: state.pageIndex.value == 0
? ColorUtil.Color_255_255_255
: ColorUtil.Color_108_108_108),
),
Container(
width: 8.w,
height: 8.h,
margin: const EdgeInsets.only(left: 6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: state.pageIndex.value == 1
? ColorUtil.Color_255_255_255
: ColorUtil.Color_108_108_108),
)
],
),
),
],
)
: Container()),
// //
Visibility( Visibility(
visible: state.pageState.value == 2, visible: state.pageState.value == 2,
@ -1472,8 +1515,8 @@ class MeetingMainPageState extends State<MeetingMainPage> {
); );
} }
/// /// -
Widget returnPage(int position){ Widget returnPageToOther(int position){
var pageList = []; var pageList = [];
/// ///
pageList.add(Stack( pageList.add(Stack(
@ -1542,11 +1585,11 @@ class MeetingMainPageState extends State<MeetingMainPage> {
crossAxisCount: 2, crossAxisCount: 2,
childAspectRatio: 0.8, childAspectRatio: 0.8,
crossAxisSpacing: 0), crossAxisSpacing: 0),
itemCount: state.videoUsers.value.length, itemCount: state.cacheUsers.value.length,
itemBuilder: (BuildContext ctx, index) { itemBuilder: (BuildContext ctx, index) {
return Stack( return Stack(
children: [ children: [
state.videoUsers.value[index].uid == state.cacheUsers.value[index].enableCamera == true ? state.cacheUsers.value[index].uid ==
UserStore.to.userInfoEntity.value!.uid UserStore.to.userInfoEntity.value!.uid
? AgoraVideoView( ? AgoraVideoView(
controller: VideoViewController( controller: VideoViewController(
@ -1559,10 +1602,14 @@ class MeetingMainPageState extends State<MeetingMainPage> {
rtcEngine: state.rctEngine.value!, rtcEngine: state.rctEngine.value!,
canvas: VideoCanvas( canvas: VideoCanvas(
uid: int.tryParse( uid: int.tryParse(
state.videoUsers.value[index].uid), setupMode: VideoViewSetupMode.videoViewSetupAdd), state.cacheUsers.value[index].uid), setupMode: VideoViewSetupMode.videoViewSetupAdd),
connection: RtcConnection( connection: RtcConnection(
channelId: state.roomNumber.value), channelId: state.roomNumber.value),
), ),
)
:
Container(
color: Colors.amber,
), ),
Positioned( Positioned(
left: 4, left: 4,
@ -1570,7 +1617,7 @@ class MeetingMainPageState extends State<MeetingMainPage> {
child: Row( child: Row(
children: [ children: [
Visibility( Visibility(
visible: state.videoUsers.value[index].uid == UserStore.to.userInfoEntity.value!.uid, visible: state.cacheUsers.value[index].uid == UserStore.to.userInfoEntity.value!.uid,
child: Image.asset( child: Image.asset(
'assets/images/meeting_main_own.png', 'assets/images/meeting_main_own.png',
width: 24.w, width: 24.w,
@ -1585,7 +1632,7 @@ class MeetingMainPageState extends State<MeetingMainPage> {
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2), borderRadius: BorderRadius.circular(2),
color: ColorUtil.Color_0_0_0_96), color: ColorUtil.Color_0_0_0_96),
child: state.videoUsers.value[index].enableMicr == true child: state.cacheUsers.value[index].enableMicr == true
? Row( ? Row(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.center, MainAxisAlignment.center,
@ -1597,7 +1644,7 @@ class MeetingMainPageState extends State<MeetingMainPage> {
height: 20.h, height: 20.h,
child: LiquidCustomProgressIndicator( child: LiquidCustomProgressIndicator(
value: value:
state.videoUsers.value[index] state.cacheUsers.value[index]
.volume ?? .volume ??
0.0, 0.0,
valueColor: valueColor:
@ -1611,7 +1658,7 @@ class MeetingMainPageState extends State<MeetingMainPage> {
.getMicrpphonePath()), .getMicrpphonePath()),
), ),
Text( Text(
state.videoUsers.value[index].userName, state.cacheUsers.value[index].userName,
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
color: ColorUtil color: ColorUtil
@ -1631,7 +1678,187 @@ class MeetingMainPageState extends State<MeetingMainPage> {
height: 20.h, height: 20.h,
), ),
Text( Text(
state.videoUsers.value[index].userName, state.cacheUsers.value[index].userName,
style: TextStyle(
fontSize: 12.sp,
color: ColorUtil
.Color_255_255_255),
)
],
),
)
],
),
)
],
);
}),
));
return pageList[position];
}
/// -
Widget returnPageSelf(int position){
var pageList = [];
///
pageList.add(Stack(
alignment: Alignment.center,
children: [
AgoraVideoView(
controller: VideoViewController(
rtcEngine: state.rctEngine.value!,
canvas: const VideoCanvas(uid: 0, setupMode: VideoViewSetupMode.videoViewSetupAdd),
),
),
Positioned(
bottom: 110,
child: GestureDetector(
child: Image.asset(
'assets/images/meeting_main_hang_up.png',
width: 50.w,
height: 50.h,
),
onTap: () {
},
),
),
Positioned(
top: 16,
right: 16,
child: Container(
height: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
color: ColorUtil.Color_0_0_0_96),
padding: const EdgeInsets.only(left: 12, right: 12),
child: Row(
children: [
Text(
'正在讲话:',
style: TextStyle(
fontSize: 10.sp,
color: ColorUtil.Color_185_184_184),
),
Image.asset(
'assets/images/meeting_main_speak2.png',
width: 20.w,
height: 20.h,
),
Text(
'晓晓',
style: TextStyle(
fontSize: 10.sp,
color: ColorUtil.Color_185_184_184),
)
],
),
),
),
],
));
/// gridview
pageList.add(Container(
color: ColorUtil.Color_57_57_57,
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 0.8,
crossAxisSpacing: 0),
itemCount: state.cacheUsers.value.length,
itemBuilder: (BuildContext ctx, index) {
return Stack(
children: [
state.cacheUsers.value[index].enableCamera == true ? state.cacheUsers.value[index].uid ==
UserStore.to.userInfoEntity.value!.uid
? AgoraVideoView(
controller: VideoViewController(
rtcEngine: state.rctEngine.value!,
canvas: const VideoCanvas(uid: 0, setupMode: VideoViewSetupMode.videoViewSetupAdd)
),
)
: AgoraVideoView(
controller: VideoViewController.remote(
rtcEngine: state.rctEngine.value!,
canvas: VideoCanvas(
uid: int.tryParse(
state.cacheUsers.value[index].uid), setupMode: VideoViewSetupMode.videoViewSetupAdd),
connection: RtcConnection(
channelId: state.roomNumber.value),
),
)
:
Container(
color: Colors.amber,
),
Positioned(
left: 4,
bottom: 4,
child: Row(
children: [
Visibility(
visible: state.cacheUsers.value[index].uid == UserStore.to.userInfoEntity.value!.uid,
child: Image.asset(
'assets/images/meeting_main_own.png',
width: 24.w,
height: 24.h,
),
),
Container(
height: 20,
margin: const EdgeInsets.only(left: 4),
padding:
const EdgeInsets.only(left: 4, right: 4),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: ColorUtil.Color_0_0_0_96),
child: state.cacheUsers.value[index].enableMicr == true
? Row(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
SizedBox(
width: 20.w,
height: 20.h,
child: LiquidCustomProgressIndicator(
value:
state.cacheUsers.value[index]
.volume ??
0.0,
valueColor:
const AlwaysStoppedAnimation(
ColorUtil
.Color_2_177_136),
backgroundColor:
ColorUtil.Color_255_255_255,
direction: Axis.vertical,
shapePath: ViewSvgPath
.getMicrpphonePath()),
),
Text(
state.cacheUsers.value[index].userName,
style: TextStyle(
fontSize: 12.sp,
color: ColorUtil
.Color_255_255_255),
)
],
)
: Row(
mainAxisAlignment:
MainAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Image.asset(
'assets/images/meeting_main_microphone_open.png',
width: 20.w,
height: 20.h,
),
Text(
state.cacheUsers.value[index].userName,
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
color: ColorUtil color: ColorUtil