mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: 改善视频尺寸文案与体验
This commit is contained in:
@@ -81,8 +81,10 @@ class PlPlayerController {
|
|||||||
|
|
||||||
final Rx<String> _direction = 'horizontal'.obs;
|
final Rx<String> _direction = 'horizontal'.obs;
|
||||||
|
|
||||||
final Rx<BoxFit> _videoFit = Rx(BoxFit.contain);
|
final Rx<BoxFit> _videoFit = Rx(videoFitType.first['attr']);
|
||||||
final Rx<String> _videoFitDesc = Rx('包含');
|
final Rx<String> _videoFitDesc = Rx(videoFitType.first['desc']);
|
||||||
|
late StreamSubscription<Duration> _bufferedListenerForVideoFit;
|
||||||
|
late StreamSubscription<Duration> _bufferedListenerForEnterFullscreen;
|
||||||
|
|
||||||
///
|
///
|
||||||
// ignore: prefer_final_fields
|
// ignore: prefer_final_fields
|
||||||
@@ -108,13 +110,14 @@ class PlPlayerController {
|
|||||||
|
|
||||||
// final Durations durations;
|
// final Durations durations;
|
||||||
|
|
||||||
List<Map<String, dynamic>> videoFitType = [
|
static List<Map<String, dynamic>> videoFitType = [
|
||||||
{'attr': BoxFit.contain, 'desc': '包含'},
|
{'attr': BoxFit.contain, 'desc': '自动', 'toast': '缩放至播放器尺寸,保留黑边'},
|
||||||
{'attr': BoxFit.cover, 'desc': '覆盖'},
|
{'attr': BoxFit.cover, 'desc': '裁剪', 'toast': '缩放至填满播放器,裁剪超出部分'},
|
||||||
{'attr': BoxFit.fill, 'desc': '填充'},
|
{'attr': BoxFit.fill, 'desc': '拉伸', 'toast': '拉伸至播放器尺寸,将产生变形'},
|
||||||
{'attr': BoxFit.fitHeight, 'desc': '高度适应'},
|
{'attr': BoxFit.none, 'desc': '原始', 'toast': '不缩放,以视频原始尺寸显示'},
|
||||||
{'attr': BoxFit.fitWidth, 'desc': '宽度适应'},
|
{'attr': BoxFit.fitHeight, 'desc': '等高', 'toast': '缩放至撑满播放器高度'},
|
||||||
{'attr': BoxFit.scaleDown, 'desc': '缩小适应'},
|
{'attr': BoxFit.fitWidth, 'desc': '等宽', 'toast': '缩放至撑满播放器宽度'},
|
||||||
|
{'attr': BoxFit.scaleDown, 'desc': '限制', 'toast': '仅超出时缩小至播放器尺寸'},
|
||||||
];
|
];
|
||||||
|
|
||||||
PreferredSizeWidget? headerControl;
|
PreferredSizeWidget? headerControl;
|
||||||
@@ -870,7 +873,7 @@ class PlPlayerController {
|
|||||||
context: Get.context!,
|
context: Get.context!,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('画面比例'),
|
title: const Text('视频尺寸'),
|
||||||
content: StatefulBuilder(builder: (context, StateSetter setState) {
|
content: StatefulBuilder(builder: (context, StateSetter setState) {
|
||||||
return Wrap(
|
return Wrap(
|
||||||
alignment: WrapAlignment.start,
|
alignment: WrapAlignment.start,
|
||||||
@@ -912,13 +915,33 @@ class PlPlayerController {
|
|||||||
Future<void> setVideoFit() async {
|
Future<void> setVideoFit() async {
|
||||||
List attrs = videoFitType.map((e) => e['attr']).toList();
|
List attrs = videoFitType.map((e) => e['attr']).toList();
|
||||||
int index = attrs.indexOf(_videoFit.value);
|
int index = attrs.indexOf(_videoFit.value);
|
||||||
|
SmartDialog.showToast(videoFitType[index]['toast'],
|
||||||
|
displayTime: const Duration(seconds: 1));
|
||||||
videoStorage.put(VideoBoxKey.cacheVideoFit, index);
|
videoStorage.put(VideoBoxKey.cacheVideoFit, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 读取fit
|
/// 读取fit
|
||||||
Future<void> getVideoFit() async {
|
Future<void> getVideoFit() async {
|
||||||
int fitValue = videoStorage.get(VideoBoxKey.cacheVideoFit, defaultValue: 0);
|
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'];
|
_videoFitDesc.value = videoFitType[fitValue]['desc'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user