fix:播放切换问题修复

This commit is contained in:
zengyi 2025-09-24 16:00:55 +08:00
parent 5fc3edfbe4
commit 9c223bd2d1
4 changed files with 58 additions and 20 deletions

View File

@ -21,6 +21,7 @@ class KtExploreLogic extends GetxController {
final PageController pageController = PageController(viewportFraction: .95);
final int preloadRange = 1;
bool isRefresh = false;
final mainLogic = Get.find<KtMainLogic>();
@override
void onReady() {
@ -123,10 +124,10 @@ class KtExploreLogic extends GetxController {
});
}
if (state.controllers[index] != null) {
state.controllers[index]?.play();
if (mainLogic.curIndex == 1) state.controllers[index]?.play();
} else {
if (!isToggle) await _initializeController(index);
state.controllers[index]?.play();
if (mainLogic.curIndex == 1) state.controllers[index]?.play();
}
//
_preloadAdjacentVideos();
@ -165,13 +166,16 @@ class KtExploreLogic extends GetxController {
try {
await controller.initialize();
final mainLogic = Get.find<KtMainLogic>();
if (index == state.currentPage && mainLogic.curIndex == 1) {
controller.play();
update();
}
controller.addListener(() {
if (state.currentPage == index && mainLogic.curIndex == 1) update();
if (state.currentPage == index && mainLogic.curIndex == 1) {
update();
} else {
controller.pause();
}
if (controller.value.isCompleted && !controller.value.isBuffering) {
onPageChanged(index + 1, isToggle: true);

View File

@ -29,7 +29,7 @@ class _KtExplorePageState extends State<KtExplorePage>
super.build(context);
return GetBuilder<KtExploreLogic>(
builder: (ctrl) {
if(Get.find<KtMainLogic>().curIndex != 1) return Container();
if (Get.find<KtMainLogic>().curIndex != 1) return Container();
if (state.loadStatus == KtLoadStatusType.loadNoData ||
state.loadStatus == KtLoadStatusType.loadFailed) {
return KtStatusWidget(
@ -174,6 +174,20 @@ class _KtExplorePageState extends State<KtExplorePage>
),
),
),
if (videoPlayerController.value.isInitialized)
GestureDetector(
onTap: () {
videoPlayerController.value.isPlaying
? videoPlayerController.pause()
: videoPlayerController.play();
setState(() {});
},
child: Container(
width: ScreenUtil().screenWidth,
height: ScreenUtil().screenHeight,
color: Colors.transparent,
),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
@ -263,6 +277,7 @@ class _KtExplorePageState extends State<KtExplorePage>
child: Image.asset('ic_play.png'.ktIcon, width: 62.w),
),
),
],
),
),

View File

@ -96,7 +96,7 @@ class _KtHomePageState extends State<KtHomePage>
child: Text(
'Get Hooked in Seconds',
style: TextStyle(
fontSize: 12.sp,
fontSize: 11.sp,
fontWeight: FontWeight.w600,
fontStyle: FontStyle.italic,
color: Colors.white,
@ -166,7 +166,7 @@ class _KtHomePageState extends State<KtHomePage>
),
],
),
SizedBox(width: 17.w),
SizedBox(width: 15.w),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@ -184,7 +184,7 @@ class _KtHomePageState extends State<KtHomePage>
child: Row(
children: [
Image.asset('ic_star.png'.ktIcon, width: 14.w),
SizedBox(width: 4.w),
SizedBox(width: 3.w),
SizedBox(
width: 162.w,
child: Text(
@ -257,7 +257,7 @@ class _KtHomePageState extends State<KtHomePage>
SizedBox(width: 4.w),
],
),
SizedBox(height: 9.w),
SizedBox(height: 8.w),
SizedBox(
height: 117.w,
child: ListView.separated(
@ -555,14 +555,20 @@ class _KtHomePageState extends State<KtHomePage>
)
: null,
),
child: Text(
item.categoryName ?? '',
style: TextStyle(
fontSize: 14.sp,
color: Color(0xFF1E1E20),
fontWeight: state.selCategoryId == item.categoryId
? FontWeight.w600
: FontWeight.w400,
child: SizedBox(
width: ((ScreenUtil().screenWidth - 42.w) / 3) - 4.w,
child: Text(
textAlign: TextAlign.center,
item.categoryName ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14.sp,
color: Color(0xFF1E1E20),
fontWeight: state.selCategoryId == item.categoryId
? FontWeight.w600
: FontWeight.w400,
),
),
),
),

View File

@ -1,3 +1,4 @@
import 'dart:io';
import 'dart:ui';
import 'package:easy_debounce/easy_throttle.dart';
@ -9,6 +10,7 @@ import 'package:get/get.dart';
import 'package:video_player/video_player.dart';
import 'package:visibility_detector/visibility_detector.dart';
import '../../kt_model/kt_video_detail_bean.dart';
import '../../kt_utils/kt_toast_utils.dart';
import '../../kt_widgets/kt_network_image.dart';
import '../../kt_widgets/kt_status_widget.dart';
@ -201,7 +203,20 @@ class _VideoPlayPageState extends State<VideoPlayPage>
if (!isAllOver) Center(child: CircularProgressIndicator()),
],
),
GestureDetector(
onTap: () {
if (episode.isLock == true) return;
(controller?.value.isPlaying ?? true)
? controller?.pause()
: controller?.play();
setState(() {});
},
child: Container(
width: ScreenUtil().screenWidth,
height: ScreenUtil().screenHeight,
color: Colors.transparent,
),
),
if (episode.isLock == true)
Stack(
children: [
@ -261,7 +276,6 @@ class _VideoPlayPageState extends State<VideoPlayPage>
),
),
Image.asset('ic_coin.png'.ktIcon, width: 18.7.w),
],
),
),
@ -277,7 +291,6 @@ class _VideoPlayPageState extends State<VideoPlayPage>
),
),
Image.asset('ic_coin.png'.ktIcon, width: 11.2.w),
],
),
],