mod: 改善视频尺寸文案与体验

This commit is contained in:
orz12
2024-03-06 15:23:54 +08:00
parent 2a9431e4b6
commit dacc1b2b58

View File

@@ -81,8 +81,10 @@ class PlPlayerController {
final Rx<String> _direction = 'horizontal'.obs;
final Rx<BoxFit> _videoFit = Rx(BoxFit.contain);
final Rx<String> _videoFitDesc = Rx('包含');
final Rx<BoxFit> _videoFit = Rx(videoFitType.first['attr']);
final Rx<String> _videoFitDesc = Rx(videoFitType.first['desc']);
late StreamSubscription<Duration> _bufferedListenerForVideoFit;
late StreamSubscription<Duration> _bufferedListenerForEnterFullscreen;
///
// ignore: prefer_final_fields
@@ -108,13 +110,14 @@ 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': '缩小适应'},
static List<Map<String, dynamic>> videoFitType = [
{'attr': BoxFit.contain, 'desc': '自动', 'toast': '缩放至播放器尺寸,保留黑边'},
{'attr': BoxFit.cover, 'desc': '裁剪', 'toast': '缩放至填满播放器,裁剪超出部分'},
{'attr': BoxFit.fill, 'desc': '拉伸', 'toast': '拉伸至播放器尺寸,将产生变形'},
{'attr': BoxFit.none, 'desc': '原始', 'toast': '不缩放,以视频原始尺寸显示'},
{'attr': BoxFit.fitHeight, 'desc': '等高', 'toast': '缩放至撑满播放器高度'},
{'attr': BoxFit.fitWidth, 'desc': '等宽', 'toast': '缩放至撑满播放器宽度'},
{'attr': BoxFit.scaleDown, 'desc': '限制', 'toast': '仅超出时缩小至播放器尺寸'},
];
PreferredSizeWidget? headerControl;
@@ -870,7 +873,7 @@ class PlPlayerController {
context: Get.context!,
builder: (context) {
return AlertDialog(
title: const Text('画面比例'),
title: const Text('视频尺寸'),
content: StatefulBuilder(builder: (context, StateSetter setState) {
return Wrap(
alignment: WrapAlignment.start,
@@ -912,13 +915,33 @@ class PlPlayerController {
Future<void> setVideoFit() async {
List attrs = videoFitType.map((e) => e['attr']).toList();
int index = attrs.indexOf(_videoFit.value);
SmartDialog.showToast(videoFitType[index]['toast'],
displayTime: const Duration(seconds: 1));
videoStorage.put(VideoBoxKey.cacheVideoFit, index);
}
/// 读取fit
Future<void> getVideoFit() async {
int fitValue = videoStorage.get(VideoBoxKey.cacheVideoFit, defaultValue: 0);
_videoFit.value = videoFitType[fitValue]['attr'];
var attr = videoFitType[fitValue]['attr'];
// 由于none与scaleDown涉及视频原始尺寸需要等待视频加载后再设置否则尺寸会变为0出现错误
if (attr == BoxFit.none || attr == BoxFit.scaleDown) {
if (buffered.value == Duration.zero) {
attr = BoxFit.contain;
_bufferedListenerForVideoFit = buffered.listen((status) {
if (status > Duration.zero) {
_bufferedListenerForVideoFit.cancel();
int fitValue =
videoStorage.get(VideoBoxKey.cacheVideoFit, defaultValue: 0);
var attr = videoFitType[fitValue]['attr'];
if (attr == BoxFit.none || attr == BoxFit.scaleDown) {
_videoFit.value = attr;
}
}
});
}
}
_videoFit.value = attr;
_videoFitDesc.value = videoFitType[fitValue]['desc'];
}