feat: 视频视图比例调整
This commit is contained in:
@ -4,6 +4,7 @@ import 'dart:async';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:media_kit/media_kit.dart';
|
import 'package:media_kit/media_kit.dart';
|
||||||
@ -68,7 +69,7 @@ class PlPlayerController {
|
|||||||
final Rx<String> _direction = 'horizontal'.obs;
|
final Rx<String> _direction = 'horizontal'.obs;
|
||||||
|
|
||||||
Rx<bool> videoFitChanged = false.obs;
|
Rx<bool> videoFitChanged = false.obs;
|
||||||
final Rx<BoxFit> _videoFit = Rx(BoxFit.fill);
|
final Rx<BoxFit> _videoFit = Rx(BoxFit.contain);
|
||||||
|
|
||||||
///
|
///
|
||||||
// ignore: prefer_final_fields
|
// ignore: prefer_final_fields
|
||||||
@ -93,13 +94,13 @@ class PlPlayerController {
|
|||||||
|
|
||||||
// final Durations durations;
|
// final Durations durations;
|
||||||
|
|
||||||
List<BoxFit> fits = [
|
List<Map<String, dynamic>> videoFitType = [
|
||||||
BoxFit.contain,
|
{'attr': BoxFit.contain, 'desc': '包含'},
|
||||||
BoxFit.cover,
|
{'attr': BoxFit.cover, 'desc': '覆盖'},
|
||||||
BoxFit.fill,
|
{'attr': BoxFit.fill, 'desc': '填充'},
|
||||||
BoxFit.fitHeight,
|
{'attr': BoxFit.fitHeight, 'desc': '高度适应'},
|
||||||
BoxFit.fitWidth,
|
{'attr': BoxFit.fitWidth, 'desc': '宽度适应'},
|
||||||
BoxFit.scaleDown
|
{'attr': BoxFit.scaleDown, 'desc': '缩小适应'},
|
||||||
];
|
];
|
||||||
|
|
||||||
PreferredSizeWidget? headerControl;
|
PreferredSizeWidget? headerControl;
|
||||||
@ -631,10 +632,17 @@ class PlPlayerController {
|
|||||||
void toggleVideoFit() {
|
void toggleVideoFit() {
|
||||||
videoFitChangedTimer?.cancel();
|
videoFitChangedTimer?.cancel();
|
||||||
videoFitChanged.value = true;
|
videoFitChanged.value = true;
|
||||||
if (fits.indexOf(_videoFit.value) < fits.length - 1) {
|
// 范围内
|
||||||
_videoFit.value = fits[fits.indexOf(_videoFit.value) + 1];
|
List attrs = videoFitType.map((e) => e['attr']).toList();
|
||||||
|
if (attrs.indexOf(_videoFit.value) < attrs.length - 1) {
|
||||||
|
int index = attrs.indexOf(_videoFit.value);
|
||||||
|
_videoFit.value = attrs[index + 1];
|
||||||
|
print(videoFitType[index + 1]['desc']);
|
||||||
|
SmartDialog.showToast(videoFitType[index + 1]['desc']);
|
||||||
} else {
|
} else {
|
||||||
_videoFit.value = fits[0];
|
// 默认 contain
|
||||||
|
_videoFit.value = videoFitType.first['attr'];
|
||||||
|
SmartDialog.showToast(videoFitType.first['desc']);
|
||||||
}
|
}
|
||||||
videoFitChangedTimer = Timer(const Duration(seconds: 1), () {
|
videoFitChangedTimer = Timer(const Duration(seconds: 1), () {
|
||||||
videoFitChangedTimer = null;
|
videoFitChangedTimer = null;
|
||||||
@ -655,9 +663,10 @@ class PlPlayerController {
|
|||||||
|
|
||||||
/// 读取fit
|
/// 读取fit
|
||||||
Future<void> getVideoFit() async {
|
Future<void> getVideoFit() async {
|
||||||
String fitValue = videoStorage.get(VideoBoxKey.videoBrightness,
|
String fitValue =
|
||||||
defaultValue: 'fitHeight');
|
videoStorage.get(VideoBoxKey.videoBrightness, defaultValue: 'contain');
|
||||||
_videoFit.value = fits.firstWhere((element) => element.name == fitValue);
|
_videoFit.value = videoFitType
|
||||||
|
.firstWhere((element) => element['attr'] == fitValue)['attr'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 缓存亮度
|
/// 缓存亮度
|
||||||
|
@ -130,15 +130,15 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
// ),
|
// ),
|
||||||
// ),
|
// ),
|
||||||
// ),
|
// ),
|
||||||
// ComBtn(
|
ComBtn(
|
||||||
// icon: const Icon(
|
icon: const Icon(
|
||||||
// Icons.fit_screen_sharp,
|
Icons.settings_overscan_outlined,
|
||||||
// size: 18,
|
size: 18,
|
||||||
// color: Colors.white,
|
color: Colors.white,
|
||||||
// ),
|
),
|
||||||
// fuc: () => _.toggleVideoFit(),
|
fuc: () => _.toggleVideoFit(),
|
||||||
// ),
|
),
|
||||||
// const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
// 全屏
|
// 全屏
|
||||||
Obx(
|
Obx(
|
||||||
() => ComBtn(
|
() => ComBtn(
|
||||||
|
Reference in New Issue
Block a user