Merge branch 'opt-videoPlayerControl' into design

This commit is contained in:
guozhigq
2024-11-26 23:31:45 +08:00
8 changed files with 105 additions and 150 deletions

View File

@ -6,6 +6,7 @@ import 'dart:typed_data';
import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_volume_controller/flutter_volume_controller.dart';
import 'package:get/get.dart';
import 'package:hive/hive.dart';
@ -113,12 +114,13 @@ class PlPlayerController {
// final Durations durations;
List<Map<String, dynamic>> videoFitType = [
{'attr': BoxFit.contain, 'desc': '包含'},
{'attr': BoxFit.cover, 'desc': '覆盖'},
{'attr': BoxFit.fill, 'desc': ''},
{'attr': BoxFit.fitHeight, 'desc': '度适应'},
{'attr': BoxFit.fitWidth, 'desc': '度适应'},
{'attr': BoxFit.scaleDown, 'desc': '小适应'},
{'attr': BoxFit.contain, 'desc': '自动'},
{'attr': BoxFit.cover, 'desc': '铺满'},
{'attr': BoxFit.fill, 'desc': ''},
{'attr': BoxFit.fitHeight, 'desc': ''},
{'attr': BoxFit.fitWidth, 'desc': ''},
{'attr': BoxFit.scaleDown, 'desc': ''},
{'attr': BoxFit.none, 'desc': '原始'},
];
PreferredSizeWidget? headerControl;
@ -828,47 +830,53 @@ class PlPlayerController {
}
/// Toggle Change the videofit accordingly
void toggleVideoFit() {
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('画面比例'),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return Wrap(
alignment: WrapAlignment.start,
void toggleVideoFit(String toggleType) {
if (toggleType == 'press') {
final String videoFitDEsc = _videoFitDesc.value;
final int index = videoFitType.indexWhere(
(element) => element['desc'] == videoFitDEsc,
);
final int newIndex = index + 1 >= videoFitType.length ? 0 : index + 1;
_videoFit.value = videoFitType[newIndex]['attr'];
_videoFitDesc.value = videoFitType[newIndex]['desc'];
setVideoFit();
SmartDialog.showToast('画面比例:${videoFitType[newIndex]['desc']}');
} else {
void onPressed(item) {
_videoFit.value = item['attr'];
_videoFitDesc.value = item['desc'];
setVideoFit();
Navigator.of(Get.context!).pop();
}
showDialog(
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('画面比例'),
content: Wrap(
spacing: 8,
runSpacing: 2,
children: [
for (var i in videoFitType) ...[
if (_videoFit.value == i['attr']) ...[
FilledButton(
onPressed: () async {
_videoFit.value = i['attr'];
_videoFitDesc.value = i['desc'];
setVideoFit();
Get.back();
},
onPressed: () => onPressed(i),
child: Text(i['desc']),
),
] else ...[
FilledButton.tonal(
onPressed: () async {
_videoFit.value = i['attr'];
_videoFitDesc.value = i['desc'];
setVideoFit();
Get.back();
},
onPressed: () => onPressed(i),
child: Text(i['desc']),
),
]
]
],
);
}),
);
},
);
),
);
},
);
}
}
/// 缓存fit

View File

@ -301,16 +301,22 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
/// 画面比例
BottomControlType.fit: SizedBox(
width: 45,
height: 30,
child: TextButton(
onPressed: () => _.toggleVideoFit(),
onPressed: () => _.toggleVideoFit('press'),
onLongPress: () => _.toggleVideoFit('longPress'),
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
child: Obx(
() => Text(
_.videoFitDEsc.value,
style: const TextStyle(color: Colors.white, fontSize: 13),
style: const TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
),
),
@ -320,29 +326,49 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
BottomControlType.speed: SizedBox(
width: 45,
height: 34,
child: TextButton(
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
onPressed: () {},
child: Obx(
() => Text(
'${_.playbackSpeed.toString()}X',
style: textStyle,
child: PopupMenuButton<double>(
tooltip: '更改播放速度',
onSelected: (double value) {
_.setPlaybackSpeed(value);
},
initialValue: _.playbackSpeed,
color: Colors.black.withOpacity(0.8),
itemBuilder: (BuildContext context) {
return _.speedsList.map((double speed) {
return PopupMenuItem<double>(
height: 40,
padding: const EdgeInsets.only(left: 20),
value: speed,
child: Text(
'${speed}x',
style: textStyle.copyWith(fontWeight: FontWeight.bold),
),
);
}).toList();
},
child: Container(
width: 45,
height: 34,
alignment: Alignment.center,
margin: const EdgeInsets.only(right: 4),
child: Obx(
() => Text(
'${_.playbackSpeed.toString()}x',
style: textStyle.copyWith(fontWeight: FontWeight.bold),
),
),
),
),
),
/// 字幕
/// 全屏
BottomControlType.fullscreen: ComBtn(
icon: Obx(
() => Icon(
() => Image.asset(
_.isFullScreen.value
? FontAwesomeIcons.compress
: FontAwesomeIcons.expand,
size: 15,
? 'assets/images/video/fullscreen_exit.png'
: 'assets/images/video/fullscreen.png',
width: 19,
color: Colors.white,
),
),
@ -359,6 +385,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
BottomControlType.time,
BottomControlType.space,
BottomControlType.fit,
BottomControlType.speed,
BottomControlType.fullscreen,
];
for (var i = 0; i < userSpecifyItem.length; i++) {