pageview预加载及缓存优化,视频可以多view同时渲染

This commit is contained in:
fuenmao 2024-12-06 13:53:14 +08:00
parent 5669b0123c
commit 19c98c5173
5 changed files with 218 additions and 264 deletions

View File

@ -503,6 +503,7 @@ class MeetingMainLogic extends GetxController with RequestToolMixin{
await state.rctEngine.value?.initialize(RtcEngineContext( await state.rctEngine.value?.initialize(RtcEngineContext(
appId: state.appId, appId: state.appId,
channelProfile: ChannelProfileType.channelProfileLiveBroadcasting, channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
// logConfig:const LogConfig()
)); ));
// //

View File

@ -236,7 +236,11 @@ class MeetingMainPageState extends State<MeetingMainPage> {
logic.hangUpVideo(); logic.hangUpVideo();
}, },
onPageViewIndexChange: (index) { onPageViewIndexChange: (index) {
if(index == 0){
state.floating.value?.open(context);
}else{
state.floating.value?.close();
}
}, },
) )
: Container()), : Container()),
@ -1391,7 +1395,7 @@ class MeetingMainPageState extends State<MeetingMainPage> {
? AgoraVideoView( ? AgoraVideoView(
controller: VideoViewController( controller: VideoViewController(
rtcEngine: state.rctEngine.value!, rtcEngine: state.rctEngine.value!,
canvas: const VideoCanvas(uid: 0), canvas: const VideoCanvas(uid: 0, setupMode: VideoViewSetupMode.videoViewSetupAdd),
), ),
) )
: const CircularProgressIndicator(), : const CircularProgressIndicator(),

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart'; import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart';
import 'package:preload_page_view/preload_page_view.dart';
import 'package:wgshare/common/store/user_store.dart'; import 'package:wgshare/common/store/user_store.dart';
import '../../../common/models/meeting_room_user.dart'; import '../../../common/models/meeting_room_user.dart';
@ -44,29 +45,61 @@ class _MeetingMainVideoComponentState extends State<MeetingMainVideoComponent>{
return Stack( return Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
PageView( PreloadPageView.builder(
scrollDirection: Axis.horizontal, preloadPagesCount: 2,
reverse: false, itemCount: 2,
controller: PageController( itemBuilder: (BuildContext context, int position) => returnPage(position),
initialPage: 0, controller: PreloadPageController(initialPage: 0),
viewportFraction: 1, onPageChanged: (int position) {
keepPage: true, state.pageIndex.value = position;
), widget.onPageViewIndexChange(position);
physics: const BouncingScrollPhysics(),
pageSnapping: true,
onPageChanged: (index) {
state.pageIndex.value = index;
widget.onPageViewIndexChange(index);
}, },
children: <Widget>[ ),
Stack(
/// 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),
)
],
),
),
],
);
}
///
Widget returnPage(int position){
var pageList = [];
///
pageList.add(Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
widget.remoteUid != "" widget.remoteUid != ""
? AgoraVideoView( ? AgoraVideoView(
controller: VideoViewController( controller: VideoViewController(
rtcEngine: widget.rtcEngine, rtcEngine: widget.rtcEngine,
canvas: const VideoCanvas(uid: 0) canvas: VideoCanvas(uid: int.tryParse(widget.remoteUid), setupMode: VideoViewSetupMode.videoViewSetupAdd)
), ),
) )
: const CircularProgressIndicator(), : const CircularProgressIndicator(),
@ -115,75 +148,10 @@ class _MeetingMainVideoComponentState extends State<MeetingMainVideoComponent>{
), ),
), ),
), ),
///
/*Visibility(
visible: widget.isOpenCamera,
child: Positioned(
top: 58,
right: 13,
child: Stack(
children: [
SizedBox(
width: 120,
height: 150,
child: Center(
child: widget.isOpenCamera
? AgoraVideoView(
controller: VideoViewController(
rtcEngine: widget.rtcEngine,
canvas: const VideoCanvas(uid: 0),
),
)
: const CircularProgressIndicator(),
),
),
Positioned(
left: 4,
bottom: 4,
child: Row(
children: [
Image.asset(
'assets/images/meeting_main_own.png',
width: 20.w,
height: 15.h,
),
Container(
height: 15,
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: Row(
children: [
*/ /*Image.asset(
'assets/images/meeting_main_microphone_open.png',
width: 13.w,
height: 14.h,
),
SizedBox(width: 4.w),*/ /*
Text(
UserStore
.to.userInfoEntity.value!.userName,
style: TextStyle(
fontSize: 10.sp,
color: ColorUtil.Color_185_184_184),
)
], ],
), ));
) /// gridview
], pageList.add(Container(
),
)
],
),
),
)*/
],
),
Container(
color: ColorUtil.Color_57_57_57, color: ColorUtil.Color_57_57_57,
child: GridView.builder( child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
@ -199,7 +167,7 @@ class _MeetingMainVideoComponentState extends State<MeetingMainVideoComponent>{
? AgoraVideoView( ? AgoraVideoView(
controller: VideoViewController( controller: VideoViewController(
rtcEngine: widget.rtcEngine, rtcEngine: widget.rtcEngine,
canvas: const VideoCanvas(uid: 0) canvas: const VideoCanvas(uid: 0, setupMode: VideoViewSetupMode.videoViewSetupAdd)
), ),
) )
: AgoraVideoView( : AgoraVideoView(
@ -207,7 +175,7 @@ class _MeetingMainVideoComponentState extends State<MeetingMainVideoComponent>{
rtcEngine: widget.rtcEngine, rtcEngine: widget.rtcEngine,
canvas: VideoCanvas( canvas: VideoCanvas(
uid: int.tryParse( uid: int.tryParse(
widget.users[index].uid)), widget.users[index].uid), setupMode: VideoViewSetupMode.videoViewSetupAdd),
connection: RtcConnection( connection: RtcConnection(
channelId: widget.channelId), channelId: widget.channelId),
), ),
@ -291,37 +259,7 @@ class _MeetingMainVideoComponentState extends State<MeetingMainVideoComponent>{
], ],
); );
}), }),
), ));
], return pageList[position];
),
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),
)
],
),
),
],
);
} }
} }

View File

@ -834,6 +834,14 @@ packages:
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.5.1" version: "1.5.1"
preload_page_view:
dependency: "direct main"
description:
name: preload_page_view
sha256: "488a10c158c5c2e9ba9d77e5dbc09b1e49e37a20df2301e5ba02992eac802b7a"
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.2.0"
protobuf: protobuf:
dependency: transitive dependency: transitive
description: description:

View File

@ -82,6 +82,9 @@ dependencies:
# 悬浮拖动组件 # 悬浮拖动组件
flutter_floating: ^1.0.7 flutter_floating: ^1.0.7
# 预加载pageview
preload_page_view: ^0.2.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter