feat: 系统倍速可编辑
This commit is contained in:
@ -29,7 +29,6 @@ class BottomControl extends StatefulWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
class _BottomControlState extends State<BottomControl> {
|
class _BottomControlState extends State<BottomControl> {
|
||||||
late PlayUrlModel videoInfo;
|
late PlayUrlModel videoInfo;
|
||||||
List<PlaySpeed> playSpeed = PlaySpeed.values;
|
|
||||||
TextStyle subTitleStyle = const TextStyle(fontSize: 12);
|
TextStyle subTitleStyle = const TextStyle(fontSize: 12);
|
||||||
TextStyle titleStyle = const TextStyle(fontSize: 14);
|
TextStyle titleStyle = const TextStyle(fontSize: 14);
|
||||||
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
|
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
|
||||||
|
|||||||
@ -17,6 +17,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
Box videoStorage = GStrorage.video;
|
Box videoStorage = GStrorage.video;
|
||||||
Box settingStorage = GStrorage.setting;
|
Box settingStorage = GStrorage.setting;
|
||||||
late double playSpeedDefault;
|
late double playSpeedDefault;
|
||||||
|
late List<double> playSpeedSystem;
|
||||||
late double longPressSpeedDefault;
|
late double longPressSpeedDefault;
|
||||||
late List customSpeedsList;
|
late List customSpeedsList;
|
||||||
late bool enableAutoLongPressSpeed;
|
late bool enableAutoLongPressSpeed;
|
||||||
@ -53,6 +54,9 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
// 系统预设倍速
|
||||||
|
playSpeedSystem =
|
||||||
|
videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);
|
||||||
// 默认倍速
|
// 默认倍速
|
||||||
playSpeedDefault =
|
playSpeedDefault =
|
||||||
videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
|
videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
|
||||||
@ -64,6 +68,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
videoStorage.get(VideoBoxKey.customSpeedsList, defaultValue: []);
|
videoStorage.get(VideoBoxKey.customSpeedsList, defaultValue: []);
|
||||||
enableAutoLongPressSpeed = settingStorage
|
enableAutoLongPressSpeed = settingStorage
|
||||||
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
|
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
|
||||||
|
// 开启动态长按倍速时不展示
|
||||||
if (enableAutoLongPressSpeed) {
|
if (enableAutoLongPressSpeed) {
|
||||||
Map newItem = sheetMenu[1];
|
Map newItem = sheetMenu[1];
|
||||||
newItem['show'] = false;
|
newItem['show'] = false;
|
||||||
@ -123,7 +128,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 设定倍速弹窗
|
// 设定倍速弹窗
|
||||||
void showBottomSheet(type, i) {
|
void showBottomSheet(String type, int i) {
|
||||||
showModalBottomSheet<void>(
|
showModalBottomSheet<void>(
|
||||||
context: context,
|
context: context,
|
||||||
isScrollControlled: true,
|
isScrollControlled: true,
|
||||||
@ -159,18 +164,11 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void menuAction(type, index, id) async {
|
void menuAction(type, int index, id) async {
|
||||||
double chooseSpeed = 1.0;
|
double chooseSpeed = 1.0;
|
||||||
if (type == 'system' && id == -1) {
|
|
||||||
SmartDialog.showToast('系统预设倍速不支持删除');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 获取当前选中的倍速值
|
// 获取当前选中的倍速值
|
||||||
if (type == 'system') {
|
chooseSpeed =
|
||||||
chooseSpeed = PlaySpeed.values[index].value;
|
type == 'system' ? playSpeedSystem[index] : customSpeedsList[index];
|
||||||
} else {
|
|
||||||
chooseSpeed = customSpeedsList[index];
|
|
||||||
}
|
|
||||||
// 设置
|
// 设置
|
||||||
if (id == 1) {
|
if (id == 1) {
|
||||||
// 设置默认倍速
|
// 设置默认倍速
|
||||||
@ -182,17 +180,22 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
videoStorage.put(
|
videoStorage.put(
|
||||||
VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault);
|
VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault);
|
||||||
} else if (id == -1) {
|
} else if (id == -1) {
|
||||||
if (customSpeedsList[index] == playSpeedDefault) {
|
late List speedsList =
|
||||||
playSpeedDefault = 1.0;
|
type == 'system' ? playSpeedSystem : customSpeedsList;
|
||||||
videoStorage.put(VideoBoxKey.playSpeedDefault, playSpeedDefault);
|
if (speedsList[index] == playSpeedDefault) {
|
||||||
|
SmartDialog.showToast('默认倍速不可删除');
|
||||||
}
|
}
|
||||||
if (customSpeedsList[index] == longPressSpeedDefault) {
|
if (speedsList[index] == longPressSpeedDefault) {
|
||||||
longPressSpeedDefault = 2.0;
|
longPressSpeedDefault = 2.0;
|
||||||
videoStorage.put(
|
videoStorage.put(
|
||||||
VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault);
|
VideoBoxKey.longPressSpeedDefault, longPressSpeedDefault);
|
||||||
}
|
}
|
||||||
customSpeedsList.removeAt(index);
|
speedsList.removeAt(index);
|
||||||
await videoStorage.put(VideoBoxKey.customSpeedsList, customSpeedsList);
|
await videoStorage.put(
|
||||||
|
type == 'system'
|
||||||
|
? VideoBoxKey.playSpeedSystem
|
||||||
|
: VideoBoxKey.customSpeedsList,
|
||||||
|
speedsList);
|
||||||
}
|
}
|
||||||
setState(() {});
|
setState(() {});
|
||||||
SmartDialog.showToast('操作成功');
|
SmartDialog.showToast('操作成功');
|
||||||
@ -249,6 +252,7 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
subtitle: Text(longPressSpeedDefault.toString()),
|
subtitle: Text(longPressSpeedDefault.toString()),
|
||||||
)
|
)
|
||||||
: const SizedBox(),
|
: const SizedBox(),
|
||||||
|
if (playSpeedSystem.isNotEmpty) ...[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 14,
|
left: 14,
|
||||||
@ -272,15 +276,16 @@ class _PlaySpeedPageState extends State<PlaySpeedPage> {
|
|||||||
spacing: 8,
|
spacing: 8,
|
||||||
runSpacing: 2,
|
runSpacing: 2,
|
||||||
children: [
|
children: [
|
||||||
for (var i in PlaySpeed.values) ...[
|
for (int i = 0; i < playSpeedSystem.length; i++) ...[
|
||||||
FilledButton.tonal(
|
FilledButton.tonal(
|
||||||
onPressed: () => showBottomSheet('system', i.index),
|
onPressed: () => showBottomSheet('system', i),
|
||||||
child: Text(i.description),
|
child: Text(playSpeedSystem[i].toString()),
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
)
|
||||||
|
],
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(
|
padding: const EdgeInsets.only(
|
||||||
left: 14,
|
left: 14,
|
||||||
|
|||||||
@ -47,7 +47,6 @@ class HeaderControl extends StatefulWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
class _HeaderControlState extends State<HeaderControl> {
|
class _HeaderControlState extends State<HeaderControl> {
|
||||||
late PlayUrlModel videoInfo;
|
late PlayUrlModel videoInfo;
|
||||||
List<PlaySpeed> playSpeed = PlaySpeed.values;
|
|
||||||
static const TextStyle subTitleStyle = TextStyle(fontSize: 12);
|
static const TextStyle subTitleStyle = TextStyle(fontSize: 12);
|
||||||
static const TextStyle titleStyle = TextStyle(fontSize: 14);
|
static const TextStyle titleStyle = TextStyle(fontSize: 14);
|
||||||
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
|
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
|
||||||
|
|||||||
@ -292,11 +292,19 @@ class PlPlayerController {
|
|||||||
_longPressSpeed.value = videoStorage
|
_longPressSpeed.value = videoStorage
|
||||||
.get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0);
|
.get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0);
|
||||||
}
|
}
|
||||||
|
// 自定义倍速集合
|
||||||
speedsList = List<double>.from(videoStorage
|
speedsList = List<double>.from(videoStorage
|
||||||
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
|
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
|
||||||
for (final PlaySpeed i in PlaySpeed.values) {
|
// 默认倍速
|
||||||
speedsList.add(i.value);
|
speedsList = List<double>.from(videoStorage
|
||||||
}
|
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
|
||||||
|
//playSpeedSystem
|
||||||
|
final List<double> playSpeedSystem =
|
||||||
|
videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);
|
||||||
|
|
||||||
|
// for (final PlaySpeed i in PlaySpeed.values) {
|
||||||
|
speedsList.addAll(playSpeedSystem);
|
||||||
|
// }
|
||||||
|
|
||||||
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
|
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
|
||||||
// if (status == PlayerStatus.playing) {
|
// if (status == PlayerStatus.playing) {
|
||||||
@ -676,18 +684,6 @@ class PlPlayerController {
|
|||||||
_playbackSpeed.value = speed;
|
_playbackSpeed.value = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 设置倍速
|
|
||||||
// Future<void> togglePlaybackSpeed() async {
|
|
||||||
// List<double> allowedSpeeds =
|
|
||||||
// PlaySpeed.values.map<double>((e) => e.value).toList();
|
|
||||||
// int index = allowedSpeeds.indexOf(_playbackSpeed.value);
|
|
||||||
// if (index < allowedSpeeds.length - 1) {
|
|
||||||
// setPlaybackSpeed(allowedSpeeds[index + 1]);
|
|
||||||
// } else {
|
|
||||||
// setPlaybackSpeed(allowedSpeeds[0]);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/// 播放视频
|
/// 播放视频
|
||||||
/// TODO _duration.value丢失
|
/// TODO _duration.value丢失
|
||||||
Future<void> play(
|
Future<void> play(
|
||||||
|
|||||||
@ -1,39 +1,15 @@
|
|||||||
enum PlaySpeed {
|
List<double> generatePlaySpeedList() {
|
||||||
pointTwoFive,
|
List<double> playSpeed = [];
|
||||||
pointFive,
|
double startSpeed = 0.25;
|
||||||
pointSevenFive,
|
double endSpeed = 2.0;
|
||||||
|
double increment = 0.25;
|
||||||
|
|
||||||
one,
|
for (double speed = startSpeed; speed <= endSpeed; speed += increment) {
|
||||||
onePointTwoFive,
|
playSpeed.add(speed);
|
||||||
onePointFive,
|
}
|
||||||
onePointSevenFive,
|
|
||||||
|
|
||||||
two,
|
return playSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
extension PlaySpeedExtension on PlaySpeed {
|
// 导出 playSpeed 列表
|
||||||
static final List<String> _descList = [
|
List<double> playSpeed = generatePlaySpeedList();
|
||||||
'0.25',
|
|
||||||
'0.5',
|
|
||||||
'0.75',
|
|
||||||
'正常',
|
|
||||||
'1.25',
|
|
||||||
'1.5',
|
|
||||||
'1.75',
|
|
||||||
'2.0',
|
|
||||||
];
|
|
||||||
String get description => _descList[index];
|
|
||||||
|
|
||||||
static final List<double> _valueList = [
|
|
||||||
0.25,
|
|
||||||
0.5,
|
|
||||||
0.75,
|
|
||||||
1.0,
|
|
||||||
1.25,
|
|
||||||
1.5,
|
|
||||||
1.75,
|
|
||||||
2.0,
|
|
||||||
];
|
|
||||||
double get value => _valueList[index];
|
|
||||||
double get defaultValue => _valueList[3];
|
|
||||||
}
|
|
||||||
|
|||||||
@ -181,6 +181,8 @@ class VideoBoxKey {
|
|||||||
videoSpeed = 'videoSpeed',
|
videoSpeed = 'videoSpeed',
|
||||||
// 播放顺序
|
// 播放顺序
|
||||||
playRepeat = 'playRepeat',
|
playRepeat = 'playRepeat',
|
||||||
|
// 系统预设倍速
|
||||||
|
playSpeedSystem = 'playSpeedSystem',
|
||||||
// 默认倍速
|
// 默认倍速
|
||||||
playSpeedDefault = 'playSpeedDefault',
|
playSpeedDefault = 'playSpeedDefault',
|
||||||
// 默认长按倍速
|
// 默认长按倍速
|
||||||
|
|||||||
Reference in New Issue
Block a user