feat: 重构选集功能,播放器添加选集,修复连播退全屏、无法保存已看完状态

This commit is contained in:
orz12
2024-04-06 00:06:57 +08:00
parent df461c2375
commit 3776cfee35
15 changed files with 728 additions and 674 deletions

View File

@@ -85,6 +85,7 @@ class PlPlayerController {
final Rx<String> _videoFitDesc = Rx(videoFitType.first['desc']);
late StreamSubscription<DataStatus> _dataListenerForVideoFit;
late StreamSubscription<DataStatus> _dataListenerForEnterFullscreen;
/// 后台播放
final Rx<bool> _backgroundPlay = false.obs;
@@ -126,6 +127,9 @@ class PlPlayerController {
PreferredSizeWidget? bottomControl;
Widget? danmuWidget;
String get bvid => _bvid;
int get cid => _cid;
/// 数据加载监听
Stream<DataStatus> get onDataStatusChanged => dataStatus.status.stream;
@@ -620,7 +624,7 @@ class PlPlayerController {
} else {
// playerStatus.status.value = PlayerStatus.playing;
}
makeHeartBeat(positionSeconds.value, type: 'status');
makeHeartBeat(positionSeconds.value, type: 'completed');
}),
videoPlayerController!.stream.position.listen((event) {
_position.value = event;
@@ -1100,15 +1104,17 @@ class PlPlayerController {
if (videoType.value == 'live') {
return;
}
bool isComplete = playerStatus.status.value == PlayerStatus.completed ||
type == 'completed';
// 播放状态变化时,更新
if (type == 'status') {
if (type == 'status' || type == 'completed') {
await VideoHttp.heartBeat(
bvid: _bvid,
cid: _cid,
progress:
playerStatus.status.value == PlayerStatus.completed ? -1 : progress,
progress: isComplete ? -1 : progress,
);
} else
return;
}
// 正常播放时间隔5秒更新一次
if (progress - _heartDuration >= 5) {
_heartDuration = progress;

View File

@@ -0,0 +1,12 @@
enum BottomControlType {
pre,
playOrPause,
next,
time,
space,
episode,
fit,
subtitle,
speed,
fullscreen,
}

View File

@@ -1,5 +1,8 @@
import 'dart:async';
import 'dart:ui';
import 'package:PiliPalaX/pages/video/detail/introduction/controller.dart';
import 'package:PiliPalaX/utils/id_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_volume_controller/flutter_volume_controller.dart';
@@ -8,37 +11,48 @@ import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:nil/nil.dart';
import 'package:PiliPalaX/plugin/pl_player/controller.dart';
import 'package:PiliPalaX/plugin/pl_player/models/duration.dart';
import 'package:PiliPalaX/plugin/pl_player/models/fullscreen_mode.dart';
import 'package:PiliPalaX/plugin/pl_player/utils.dart';
import 'package:PiliPalaX/utils/feed_back.dart';
import 'package:PiliPalaX/utils/storage.dart';
import 'package:media_kit_video/media_kit_video_controls/src/controls/methods/video_state.dart';
import 'package:screen_brightness/screen_brightness.dart';
import '../../common/widgets/audio_video_progress_bar.dart';
import '../../models/video_detail_res.dart';
import '../../pages/bangumi/introduction/controller.dart';
import '../../common/widgets/list_sheet.dart';
import '../../utils/utils.dart';
import 'models/bottom_control_type.dart';
import 'models/bottom_progress_behavior.dart';
import 'widgets/app_bar_ani.dart';
import 'widgets/backward_seek.dart';
import 'widgets/bottom_control.dart';
import 'widgets/common_btn.dart';
import 'widgets/forward_seek.dart';
import 'widgets/play_pause_btn.dart';
class PLVideoPlayer extends StatefulWidget {
const PLVideoPlayer({
required this.controller,
this.videoIntroController,
this.bangumiIntroController,
this.headerControl,
this.bottomControl,
this.danmuWidget,
this.bottomList,
super.key,
});
final PlPlayerController controller;
final VideoIntroController? videoIntroController;
final BangumiIntroController? bangumiIntroController;
final PreferredSizeWidget? headerControl;
final PreferredSizeWidget? bottomControl;
final Widget? danmuWidget;
final List<BottomControlType>? bottomList;
@override
State<PLVideoPlayer> createState() => _PLVideoPlayerState();
@@ -48,27 +62,25 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
with TickerProviderStateMixin {
late AnimationController animationController;
late VideoController videoController;
final PLVideoPlayerController _ctr = Get.put(PLVideoPlayerController());
late VideoIntroController? videoIntroController;
late BangumiIntroController? bangumiIntroController;
final GlobalKey _playerKey = GlobalKey();
// bool _mountSeekBackwardButton = false;
// bool _mountSeekForwardButton = false;
// bool _hideSeekBackwardButton = false;
// bool _hideSeekForwardButton = false;
final RxBool _mountSeekBackwardButton = false.obs;
final RxBool _mountSeekForwardButton = false.obs;
final RxBool _hideSeekBackwardButton = false.obs;
final RxBool _hideSeekForwardButton = false.obs;
// double _brightnessValue = 0.0;
// bool _brightnessIndicator = false;
final RxDouble _brightnessValue = 0.0.obs;
final RxBool _brightnessIndicator = false.obs;
Timer? _brightnessTimer;
// double _volumeValue = 0.0;
// bool _volumeIndicator = false;
final RxDouble _volumeValue = 0.0.obs;
final RxBool _volumeIndicator = false.obs;
Timer? _volumeTimer;
double _distance = 0.0;
// 初始手指落下位置
// double _initTapPositoin = 0.0;
// bool _volumeInterceptEventStream = false;
final RxDouble _distance = 0.0.obs;
final RxBool _volumeInterceptEventStream = false.obs;
Box setting = GStrorage.setting;
late FullScreenMode mode;
@@ -87,11 +99,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
double _lastAnnouncedValue = -1;
void onDoubleTapSeekBackward() {
_ctr.onDoubleTapSeekBackward();
_mountSeekBackwardButton.value = true;
}
void onDoubleTapSeekForward() {
_ctr.onDoubleTapSeekForward();
_mountSeekForwardButton.value = true;
}
// 双击播放、暂停
@@ -126,6 +138,8 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
animationController = AnimationController(
vsync: this, duration: const Duration(milliseconds: 100));
videoController = widget.controller.videoController!;
videoIntroController = widget.videoIntroController;
bangumiIntroController = widget.bangumiIntroController;
widget.controller.headerControl = widget.headerControl;
widget.controller.bottomControl = widget.bottomControl;
widget.controller.danmuWidget = widget.danmuWidget;
@@ -138,10 +152,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Future.microtask(() async {
try {
FlutterVolumeController.updateShowSystemUI(true);
_ctr.volumeValue.value = (await FlutterVolumeController.getVolume())!;
_volumeValue.value = (await FlutterVolumeController.getVolume())!;
FlutterVolumeController.addListener((double value) {
if (mounted && !_ctr.volumeInterceptEventStream.value) {
_ctr.volumeValue.value = value;
if (mounted && !_volumeInterceptEventStream.value) {
_volumeValue.value = value;
}
});
} catch (_) {}
@@ -149,10 +163,10 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
Future.microtask(() async {
try {
_ctr.brightnessValue.value = await ScreenBrightness().current;
_brightnessValue.value = await ScreenBrightness().current;
ScreenBrightness().onCurrentBrightnessChanged.listen((double value) {
if (mounted) {
_ctr.brightnessValue.value = value;
_brightnessValue.value = value;
}
});
} catch (_) {}
@@ -164,14 +178,14 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
FlutterVolumeController.updateShowSystemUI(false);
await FlutterVolumeController.setVolume(value);
} catch (_) {}
_ctr.volumeValue.value = value;
_ctr.volumeIndicator.value = true;
_ctr.volumeInterceptEventStream.value = true;
_volumeValue.value = value;
_volumeIndicator.value = true;
_volumeInterceptEventStream.value = true;
_volumeTimer?.cancel();
_volumeTimer = Timer(const Duration(milliseconds: 200), () {
if (mounted) {
_ctr.volumeIndicator.value = false;
_ctr.volumeInterceptEventStream.value = false;
_volumeIndicator.value = false;
_volumeInterceptEventStream.value = false;
}
});
}
@@ -180,11 +194,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
try {
await ScreenBrightness().setScreenBrightness(value);
} catch (_) {}
_ctr.brightnessIndicator.value = true;
_brightnessIndicator.value = true;
_brightnessTimer?.cancel();
_brightnessTimer = Timer(const Duration(milliseconds: 200), () {
if (mounted) {
_ctr.brightnessIndicator.value = false;
_brightnessIndicator.value = false;
}
});
widget.controller.brightness.value = value;
@@ -197,6 +211,268 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
super.dispose();
}
// 动态构建底部控制条
List<Widget> buildBottomControl() {
final PlPlayerController _ = widget.controller;
Map<BottomControlType, Widget> videoProgressWidgets = {
/// 上一集
BottomControlType.pre: ComBtn(
icon: const Icon(
Icons.skip_previous,
size: 15,
color: Colors.white,
),
fuc: () {},
tooltip: '上一集',
),
/// 播放暂停
BottomControlType.playOrPause: PlayOrPauseButton(
controller: _,
),
/// 下一集
BottomControlType.next: ComBtn(
icon: const Icon(
Icons.skip_next,
size: 15,
color: Colors.white,
),
fuc: () {},
tooltip: '下一集',
),
/// 时间进度
BottomControlType.time: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
// 播放时间
Obx(() {
return Text(
Utils.timeFormat(_.positionSeconds.value),
style: const TextStyle(
color: Colors.white,
fontSize: 10,
height: 1.4,
fontFeatures: [FontFeature.tabularFigures()],
),
semanticsLabel:
'已播放${Utils.durationReadFormat(Utils.timeFormat(_.positionSeconds.value))}',
);
}),
// const SizedBox(width: 2),
// const ExcludeSemantics(
// child: Text(
// '/',
// style: textStyle,
// ),
// ),
// const SizedBox(width: 2),
Obx(
() => Text(
Utils.timeFormat(_.durationSeconds.value),
style: const TextStyle(
color: Color(0xFFD0D0D0),
fontSize: 10,
height: 1.4,
fontFeatures: [FontFeature.tabularFigures()],
),
semanticsLabel:
'${Utils.durationReadFormat(Utils.timeFormat(_.durationSeconds.value))}',
),
),
],
),
/// 空白占位
BottomControlType.space: const Spacer(),
/// 选集
BottomControlType.episode: Obx(() {
bool isSeason =
videoIntroController?.videoDetail.value.ugcSeason != null;
bool isPage = videoIntroController?.videoDetail.value.pages != null &&
videoIntroController!.videoDetail.value.pages!.length > 1;
bool isBangumi = bangumiIntroController?.bangumiDetail.value != null;
if (!isSeason && !isPage && !isBangumi) {
return const SizedBox.shrink();
}
return SizedBox(
width: 42,
height: 30,
child: Container(
width: 42,
height: 30,
alignment: Alignment.center,
child: ComBtn(
icon: const Icon(
Icons.list,
size: 22,
color: Colors.white,
),
tooltip: '选集',
fuc: () {
int currentCid = widget.controller.cid;
String bvid = widget.controller.bvid;
final List episodes = [];
late Function changeFucCall;
if (isSeason) {
final List<SectionItem> sections = videoIntroController!
.videoDetail.value.ugcSeason!.sections!;
for (int i = 0; i < sections.length; i++) {
final List<EpisodeItem> episodesList =
sections[i].episodes!;
episodes.addAll(episodesList);
}
changeFucCall = videoIntroController!.changeSeasonOrbangu;
} else if (isPage) {
final List<Part> pages =
videoIntroController!.videoDetail.value.pages!;
episodes.addAll(pages);
changeFucCall = videoIntroController!.changeSeasonOrbangu;
} else if (isBangumi) {
episodes.addAll(bangumiIntroController!.bangumiDetail.value.episodes!);
changeFucCall = bangumiIntroController!.changeSeasonOrbangu;
}
ListSheet(
episodes: episodes,
bvid: bvid,
aid: IdUtils.bv2av(bvid),
currentCid: currentCid,
changeFucCall: changeFucCall,
context: context,
).buildShowBottomSheet();
},
)));
}),
/// 画面比例
BottomControlType.fit: SizedBox(
width: 42,
height: 30,
child: TextButton(
onPressed: () => _.toggleVideoFit(),
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
child: Obx(
() => Text(
_.videoFitDEsc.value,
style: const TextStyle(color: Colors.white, fontSize: 13),
),
),
),
),
/// 字幕
BottomControlType.subtitle: Obx(
() => _.vttSubtitles.isEmpty
? const SizedBox.shrink()
: SizedBox(
width: 42,
height: 30,
child: PopupMenuButton<Map<String, String>>(
onSelected: (Map<String, String> value) {
_.setSubtitle(value);
},
initialValue: _.vttSubtitles[_.vttSubtitlesIndex.value],
color: Colors.black.withOpacity(0.8),
itemBuilder: (BuildContext context) {
return _.vttSubtitles.map((Map<String, String> subtitle) {
return PopupMenuItem<Map<String, String>>(
value: subtitle,
child: Text(
"${subtitle['title']}",
style: const TextStyle(color: Colors.white),
),
);
}).toList();
},
child: Container(
width: 42,
height: 30,
alignment: Alignment.center,
child: const Icon(
Icons.closed_caption_off_outlined,
size: 22,
color: Colors.white,
semanticLabel: '字幕',
),
),
),
),
),
/// 播放速度
BottomControlType.speed: SizedBox(
width: 42,
height: 30,
child: PopupMenuButton<double>(
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: 35,
padding: const EdgeInsets.only(left: 30),
value: speed,
child: Text(
"${speed}X",
style: const TextStyle(color: Colors.white, fontSize: 13),
semanticsLabel: "$speed倍速",
),
);
}).toList();
},
child: Container(
width: 42,
height: 30,
alignment: Alignment.center,
child: Obx(() => Text("${_.playbackSpeed}X",
style: const TextStyle(color: Colors.white, fontSize: 13),
semanticsLabel: "${_.playbackSpeed}倍速")),
),
),
),
/// 全屏
BottomControlType.fullscreen: SizedBox(
width: 42,
height: 30,
child: Obx(() => ComBtn(
tooltip: _.isFullScreen.value ? '退出全屏' : '全屏',
icon: Icon(
_.isFullScreen.value ? Icons.fullscreen_exit : Icons.fullscreen,
size: 24,
color: Colors.white,
),
fuc: () => _.triggerFullScreen!(status: !_.isFullScreen.value),
)),
),
};
final List<Widget> list = [];
var userSpecifyItem = widget.bottomList ??
[
BottomControlType.playOrPause,
BottomControlType.time,
// BottomControlType.pre,
// BottomControlType.next,
BottomControlType.space,
BottomControlType.episode,
BottomControlType.fit,
BottomControlType.subtitle,
BottomControlType.speed,
BottomControlType.fullscreen,
];
for (var i = 0; i < userSpecifyItem.length; i++) {
list.add(videoProgressWidgets[userSpecifyItem[i]]!);
}
return list;
}
@override
Widget build(BuildContext context) {
final PlPlayerController _ = widget.controller;
@@ -318,7 +594,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
() => Align(
child: AnimatedOpacity(
curve: Curves.easeInOut,
opacity: _ctr.volumeIndicator.value ? 1.0 : 0.0,
opacity: _volumeIndicator.value ? 1.0 : 0.0,
duration: const Duration(milliseconds: 150),
child: Container(
alignment: Alignment.center,
@@ -337,9 +613,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
width: 28.0,
alignment: Alignment.centerRight,
child: Icon(
_ctr.volumeValue.value == 0.0
_volumeValue.value == 0.0
? Icons.volume_off
: _ctr.volumeValue.value < 0.5
: _volumeValue.value < 0.5
? Icons.volume_down
: Icons.volume_up,
color: const Color(0xFFFFFFFF),
@@ -348,7 +624,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
),
Expanded(
child: Text(
'${(_ctr.volumeValue.value * 100.0).round()}%',
'${(_volumeValue.value * 100.0).round()}%',
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 13.0,
@@ -369,7 +645,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
() => Align(
child: AnimatedOpacity(
curve: Curves.easeInOut,
opacity: _ctr.brightnessIndicator.value ? 1.0 : 0.0,
opacity: _brightnessIndicator.value ? 1.0 : 0.0,
duration: const Duration(milliseconds: 150),
child: Container(
alignment: Alignment.center,
@@ -388,9 +664,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
width: 28.0,
alignment: Alignment.centerRight,
child: Icon(
_ctr.brightnessValue.value < 1.0 / 3.0
_brightnessValue.value < 1.0 / 3.0
? Icons.brightness_low
: _ctr.brightnessValue.value < 2.0 / 3.0
: _brightnessValue.value < 2.0 / 3.0
? Icons.brightness_medium
: Icons.brightness_high,
color: const Color(0xFFFFFFFF),
@@ -400,7 +676,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
const SizedBox(width: 2.0),
Expanded(
child: Text(
'${(_ctr.brightnessValue.value * 100.0).round()}%',
'${(_brightnessValue.value * 100.0).round()}%',
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 13.0,
@@ -528,7 +804,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
// 左边区域 👈
final double level = renderBox.size.height * 3;
final double brightness =
_ctr.brightnessValue.value - delta / level;
_brightnessValue.value - delta / level;
final double result = brightness.clamp(0.0, 1.0);
setBrightness(result);
} else if (tapPosition < sectionWidth * 2) {
@@ -540,28 +816,28 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
await widget.controller.triggerFullScreen(status: status);
}
if (dy > _distance && dy > threshold) {
if (dy > _distance.value && dy > threshold) {
// 下滑退出全屏/进入全屏
if (_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger(fullScreenGestureReverse);
}
_distance = 0.0;
} else if (dy < _distance && dy < -threshold) {
_distance.value = 0.0;
} else if (dy < _distance.value && dy < -threshold) {
// 上划进入全屏/退出全屏
if (!_.isFullScreen.value ^ fullScreenGestureReverse) {
fullScreenTrigger(!fullScreenGestureReverse);
}
_distance = 0.0;
_distance.value = 0.0;
}
_distance = dy;
_distance.value = dy;
} else {
// 右边区域 👈
final double level = renderBox.size.height * 0.5;
if (lastVolume < 0) {
lastVolume = _ctr.volumeValue.value;
lastVolume = _volumeValue.value;
}
final double volume =
(lastVolume + _ctr.volumeValue.value - delta / level) / 2;
(lastVolume + _volumeValue.value - delta / level) / 2;
final double result = volume.clamp(0.0, 1.0);
lastVolume = result;
setVolume(result);
@@ -596,9 +872,9 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
position: 'bottom',
child: widget.bottomControl ??
BottomControl(
controller: widget.controller,
triggerFullScreen:
widget.controller.triggerFullScreen),
controller: widget.controller,
buildBottomControl: buildBottomControl(),
),
),
),
],
@@ -618,23 +894,23 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
}
if (defaultBtmProgressBehavior ==
BtmProgresBehavior.alwaysHide.code) {
return Container();
return const SizedBox();
}
if (defaultBtmProgressBehavior ==
BtmProgresBehavior.onlyShowFullScreen.code &&
!_.isFullScreen.value) {
return Container();
return const SizedBox();
} else if (defaultBtmProgressBehavior ==
BtmProgresBehavior.onlyHideFullScreen.code &&
_.isFullScreen.value) {
return Container();
return const SizedBox();
}
if (_.videoType.value == 'live') {
return Container();
}
if (value > max || max <= 0) {
return Container();
return const SizedBox();
}
return Positioned(
bottom: -1,
@@ -752,18 +1028,17 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
/// 点击 快进/快退
Obx(
() => Visibility(
visible: _ctr.mountSeekBackwardButton.value ||
_ctr.mountSeekForwardButton.value,
visible:
_mountSeekBackwardButton.value || _mountSeekForwardButton.value,
child: Positioned.fill(
child: Row(
children: [
Expanded(
child: _ctr.mountSeekBackwardButton.value
child: _mountSeekBackwardButton.value
? TweenAnimationBuilder<double>(
tween: Tween<double>(
begin: 0.0,
end:
_ctr.hideSeekBackwardButton.value ? 0.0 : 1.0,
end: _hideSeekBackwardButton.value ? 0.0 : 1.0,
),
duration: const Duration(milliseconds: 500),
builder: (BuildContext context, double value,
@@ -773,18 +1048,16 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
child: child,
),
onEnd: () {
if (_ctr.hideSeekBackwardButton.value) {
_ctr.hideSeekBackwardButton.value = false;
_ctr.mountSeekBackwardButton.value = false;
if (_hideSeekBackwardButton.value) {
_hideSeekBackwardButton.value = false;
_mountSeekBackwardButton.value = false;
}
},
child: BackwardSeekIndicator(
onChanged: (Duration value) {
// _seekBarDeltaValueNotifier.value = -value;
},
onChanged: (Duration value) => {},
onSubmitted: (Duration value) {
_ctr.hideSeekBackwardButton.value = true;
_ctr.mountSeekBackwardButton.value = false;
_hideSeekBackwardButton.value = true;
_mountSeekBackwardButton.value = false;
final Player player =
widget.controller.videoPlayerController!;
Duration result = player.state.position - value;
@@ -797,7 +1070,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
},
),
)
: nil,
: const SizedBox(),
),
const Spacer(),
// Expanded(
@@ -806,11 +1079,11 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
// ),
// ),
Expanded(
child: _ctr.mountSeekForwardButton.value
child: _mountSeekForwardButton.value
? TweenAnimationBuilder<double>(
tween: Tween<double>(
begin: 0.0,
end: _ctr.hideSeekForwardButton.value ? 0.0 : 1.0,
end: _hideSeekForwardButton.value ? 0.0 : 1.0,
),
duration: const Duration(milliseconds: 500),
builder: (BuildContext context, double value,
@@ -820,18 +1093,16 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
child: child,
),
onEnd: () {
if (_ctr.hideSeekForwardButton.value) {
_ctr.hideSeekForwardButton.value = false;
_ctr.mountSeekForwardButton.value = false;
if (_hideSeekForwardButton.value) {
_hideSeekForwardButton.value = false;
_mountSeekForwardButton.value = false;
}
},
child: ForwardSeekIndicator(
onChanged: (Duration value) {
// _seekBarDeltaValueNotifier.value = value;
},
onChanged: (Duration value) => {},
onSubmitted: (Duration value) {
_ctr.hideSeekForwardButton.value = true;
_ctr.mountSeekForwardButton.value = false;
_hideSeekForwardButton.value = true;
_mountSeekForwardButton.value = false;
final Player player =
widget.controller.videoPlayerController!;
Duration result = player.state.position + value;
@@ -844,7 +1115,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
},
),
)
: nil,
: const SizedBox(),
),
],
),
@@ -855,31 +1126,3 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
);
}
}
class PLVideoPlayerController extends GetxController {
RxBool mountSeekBackwardButton = false.obs;
RxBool mountSeekForwardButton = false.obs;
RxBool hideSeekBackwardButton = false.obs;
RxBool hideSeekForwardButton = false.obs;
RxDouble brightnessValue = 0.0.obs;
RxBool brightnessIndicator = false.obs;
RxDouble volumeValue = 0.0.obs;
RxBool volumeIndicator = false.obs;
RxDouble distance = 0.0.obs;
// 初始手指落下位置
RxDouble initTapPositoin = 0.0.obs;
RxBool volumeInterceptEventStream = false.obs;
// 双击快进 展示样式
void onDoubleTapSeekForward() {
mountSeekForwardButton.value = true;
}
void onDoubleTapSeekBackward() {
mountSeekBackwardButton.value = true;
}
}

View File

@@ -13,9 +13,12 @@ import '../../../utils/utils.dart';
class BottomControl extends StatelessWidget implements PreferredSizeWidget {
final PlPlayerController? controller;
final Function? triggerFullScreen;
const BottomControl({this.controller, this.triggerFullScreen, Key? key})
: super(key: key);
final List<Widget>? buildBottomControl;
const BottomControl({
this.controller,
this.buildBottomControl,
Key? key,
}) : super(key: key);
@override
Size get preferredSize => const Size(double.infinity, kToolbarHeight);
@@ -95,147 +98,7 @@ class BottomControl extends StatelessWidget implements PreferredSizeWidget {
},
),
Row(
children: [
controller != null
? PlayOrPauseButton(
controller: _,
)
: nil,
// 播放时间
Obx(() {
return Text(
Utils.timeFormat(_.positionSeconds.value),
style: textStyle,
semanticsLabel:
'已播放${Utils.durationReadFormat(Utils.timeFormat(_.positionSeconds.value))}',
);
}),
const SizedBox(width: 2),
const ExcludeSemantics(
child: Text(
'/',
style: textStyle,
),
),
const SizedBox(width: 2),
Obx(
() => Text(
Utils.timeFormat(_.durationSeconds.value),
style: textStyle,
semanticsLabel:
'${Utils.durationReadFormat(Utils.timeFormat(_.durationSeconds.value))}',
),
),
const Spacer(),
SizedBox(
width: 42,
height: 30,
child: TextButton(
onPressed: () => _.toggleVideoFit(),
style: ButtonStyle(
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
child: Obx(
() => Text(
_.videoFitDEsc.value,
style: const TextStyle(color: Colors.white, fontSize: 13),
),
),
),
),
Obx(
() => _.vttSubtitles.isEmpty
? const SizedBox(
width: 0,
)
: SizedBox(
width: 42,
height: 30,
child: PopupMenuButton<Map<String, String>>(
onSelected: (Map<String, String> value) {
controller!.setSubtitle(value);
},
initialValue:
_.vttSubtitles[_.vttSubtitlesIndex.value],
color: Colors.black.withOpacity(0.8),
itemBuilder: (BuildContext context) {
return _.vttSubtitles
.map((Map<String, String> subtitle) {
return PopupMenuItem<Map<String, String>>(
value: subtitle,
child: Text(
"${subtitle['title']}",
style: const TextStyle(color: Colors.white),
),
);
}).toList();
},
child: Container(
width: 42,
height: 30,
alignment: Alignment.center,
child: const Icon(
Icons.closed_caption_off_outlined,
size: 22,
color: Colors.white,
semanticLabel: '字幕',
),
),
),
),
),
SizedBox(
width: 42,
height: 30,
child: PopupMenuButton<double>(
onSelected: (double value) {
controller!.setPlaybackSpeed(value);
},
initialValue: _.playbackSpeed,
color: Colors.black.withOpacity(0.8),
itemBuilder: (BuildContext context) {
return _.speedsList.map((double speed) {
return PopupMenuItem<double>(
height: 35,
padding: const EdgeInsets.only(left: 30),
value: speed,
child: Text(
"${speed}X",
style: const TextStyle(color: Colors.white, fontSize: 13),
semanticsLabel: "$speed倍速",
),
);
}).toList();
},
child: Container(
width: 42,
height: 30,
alignment: Alignment.center,
child: Obx(() => Text("${_.playbackSpeed}X",
style:
const TextStyle(color: Colors.white, fontSize: 13),
semanticsLabel: "${_.playbackSpeed}倍速")),
),
),
),
// 全屏
SizedBox(
width: 42,
height: 30,
child: Obx(() => ComBtn(
tooltip: _.isFullScreen.value ? '退出全屏' : '全屏',
icon: Icon(
_.isFullScreen.value
? Icons.fullscreen_exit
: Icons.fullscreen,
size: 24,
color: Colors.white,
),
fuc: () =>
triggerFullScreen!(status: !_.isFullScreen.value),
)),
),
],
children: [...buildBottomControl!],
),
const SizedBox(height: 12),
],