提交 82eec7f9 authored 作者: jungleiOS's avatar jungleiOS

增加长按倍速提示

上级 41847cfd
...@@ -16,8 +16,9 @@ import 'package:gz_video_player/widget/video_bottom_bar.dart'; ...@@ -16,8 +16,9 @@ import 'package:gz_video_player/widget/video_bottom_bar.dart';
import 'package:gz_video_player/widget/video_definition_side_bar.dart'; import 'package:gz_video_player/widget/video_definition_side_bar.dart';
import 'package:gz_video_player/widget/video_loading_view.dart'; import 'package:gz_video_player/widget/video_loading_view.dart';
import 'package:gz_video_player/widget/video_speed_bar.dart'; import 'package:gz_video_player/widget/video_speed_bar.dart';
import 'package:gz_video_player/widget/video_speed_tip.dart';
import 'package:gz_video_player/widget/video_top_bar.dart'; import 'package:gz_video_player/widget/video_top_bar.dart';
import 'package:gz_video_player/widget/vidoe_estimated_time_bar.dart'; import 'package:gz_video_player/widget/video_estimated_time_bar.dart';
import 'package:gz_video_player/widget/volume.dart'; import 'package:gz_video_player/widget/volume.dart';
import 'package:screen_brightness/screen_brightness.dart'; import 'package:screen_brightness/screen_brightness.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
...@@ -161,6 +162,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -161,6 +162,9 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
/// 是否隐藏速度栏 /// 是否隐藏速度栏
bool _hiddenSpeed = true; bool _hiddenSpeed = true;
/// 是否隐藏速度tip
bool _hiddenSpeedTip = true;
/// 倍数按钮标题 /// 倍数按钮标题
String _speedTitle = ''; String _speedTitle = '';
...@@ -852,6 +856,13 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -852,6 +856,13 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
}, },
), ),
/// 倍速提示
VideoSpeedTip(
hidden: _hiddenSpeedTip,
videoSpeedTipStyle: widget.videoStyle.videoSpeedTipStyle,
speed: _speedTitle,
),
/// 清晰度设置栏 /// 清晰度设置栏
VideoDefinitionSideBar( VideoDefinitionSideBar(
itemList: widget.playOptions.definitionList, itemList: widget.playOptions.definitionList,
...@@ -877,7 +888,11 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -877,7 +888,11 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
), ),
/// 预估时间栏 /// 预估时间栏
VideoEstimatedTimeBar(notifier: _estimatedTimeNotifier), VideoEstimatedTimeBar(
notifier: _estimatedTimeNotifier,
videoEstimatedTimeBarStyle:
widget.videoStyle.videoEstimatedTimeBarStyle,
),
widget.brightnessWidget ?? widget.brightnessWidget ??
BrightnessWidget( BrightnessWidget(
...@@ -1032,6 +1047,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -1032,6 +1047,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
_controller.setPlaybackSpeed(item.speed); _controller.setPlaybackSpeed(item.speed);
widget.onSpeedChange?.call(item); widget.onSpeedChange?.call(item);
_speedTitle = item.title; _speedTitle = item.title;
_hiddenSpeedTip = false;
setState(() {}); setState(() {});
}, },
...@@ -1041,6 +1057,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -1041,6 +1057,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
_controller.setPlaybackSpeed(_speedItem.speed); _controller.setPlaybackSpeed(_speedItem.speed);
widget.onSpeedChange?.call(_speedItem); widget.onSpeedChange?.call(_speedItem);
_speedTitle = _speedItem.title; _speedTitle = _speedItem.title;
_hiddenSpeedTip = true;
setState(() {}); setState(() {});
}, },
......
...@@ -42,3 +42,28 @@ class VideoSpeedButtonStyle { ...@@ -42,3 +42,28 @@ class VideoSpeedButtonStyle {
), ),
}); });
} }
class VideoSpeedTipStyle {
final AlignmentGeometry alignment;
final Size size;
final Widget icon;
final Decoration decoration;
final EdgeInsetsGeometry middlePadding;
final TextStyle speedTextStyle;
final TextStyle describeTextStyle;
final String describe;
VideoSpeedTipStyle({
this.alignment = const FractionalOffset(0.5, 0.2),
this.size = const Size(140.0, 40.0),
this.icon = const Icon(Icons.speed, size: 20.0, color: Colors.white),
this.decoration = const BoxDecoration(
color: Color(0x7F000000),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
this.middlePadding = const EdgeInsets.symmetric(horizontal: 14.0),
this.speedTextStyle = const TextStyle(color: Colors.blue),
this.describeTextStyle = const TextStyle(color: Colors.white),
this.describe = '快进中',
});
}
...@@ -7,6 +7,7 @@ import 'package:gz_video_player/video_speed.dart'; ...@@ -7,6 +7,7 @@ import 'package:gz_video_player/video_speed.dart';
import 'package:gz_video_player/video_subtitles.dart'; import 'package:gz_video_player/video_subtitles.dart';
import 'package:gz_video_player/video_top_bar_style.dart'; import 'package:gz_video_player/video_top_bar_style.dart';
import 'package:gz_video_player/video_volume_style.dart'; import 'package:gz_video_player/video_volume_style.dart';
import 'package:gz_video_player/widget/video_estimated_time_bar.dart';
/// 播放器样式 /// 播放器样式
class VideoStyle { class VideoStyle {
...@@ -17,6 +18,8 @@ class VideoStyle { ...@@ -17,6 +18,8 @@ class VideoStyle {
VideoLoadingStyle? videoLoadingStyle, VideoLoadingStyle? videoLoadingStyle,
VideoSpeedButtonStyle? videoSpeedButtonStyle, VideoSpeedButtonStyle? videoSpeedButtonStyle,
VideoSpeedItemStyle? videoSpeedItemStyle, VideoSpeedItemStyle? videoSpeedItemStyle,
VideoSpeedTipStyle? videoSpeedTipStyle,
VideoEstimatedTimeBarStyle? videoEstimatedTimeBarStyle,
VideoDefinitionItemStyle? videoDefinitionItemStyle, VideoDefinitionItemStyle? videoDefinitionItemStyle,
VideoDefinitionButtonStyle? videoDefinitionButtonStyle, VideoDefinitionButtonStyle? videoDefinitionButtonStyle,
VideoBrightnessStyle? videoBrightnessStyle, VideoBrightnessStyle? videoBrightnessStyle,
...@@ -43,6 +46,8 @@ class VideoStyle { ...@@ -43,6 +46,8 @@ class VideoStyle {
videoSpeedButtonStyle = videoSpeedButtonStyle =
videoSpeedButtonStyle ?? VideoSpeedButtonStyle(), videoSpeedButtonStyle ?? VideoSpeedButtonStyle(),
videoSpeedItemStyle = videoSpeedItemStyle ?? VideoSpeedItemStyle(), videoSpeedItemStyle = videoSpeedItemStyle ?? VideoSpeedItemStyle(),
videoSpeedTipStyle = videoSpeedTipStyle ?? VideoSpeedTipStyle(),
videoEstimatedTimeBarStyle = videoEstimatedTimeBarStyle ?? VideoEstimatedTimeBarStyle(),
videoDefinitionItemStyle = videoDefinitionItemStyle ?? VideoDefinitionItemStyle(), videoDefinitionItemStyle = videoDefinitionItemStyle ?? VideoDefinitionItemStyle(),
videoDefinitionButtonStyle = videoDefinitionButtonStyle ?? VideoDefinitionButtonStyle(), videoDefinitionButtonStyle = videoDefinitionButtonStyle ?? VideoDefinitionButtonStyle(),
videoBrightnessStyle = videoBrightnessStyle ?? VideoBrightnessStyle(), videoBrightnessStyle = videoBrightnessStyle ?? VideoBrightnessStyle(),
...@@ -54,6 +59,8 @@ class VideoStyle { ...@@ -54,6 +59,8 @@ class VideoStyle {
final VideoLoadingStyle videoLoadingStyle; //loading样式 final VideoLoadingStyle videoLoadingStyle; //loading样式
final VideoSpeedButtonStyle videoSpeedButtonStyle; // 倍速按钮样式 final VideoSpeedButtonStyle videoSpeedButtonStyle; // 倍速按钮样式
final VideoSpeedItemStyle videoSpeedItemStyle; // 倍速 item 样式 final VideoSpeedItemStyle videoSpeedItemStyle; // 倍速 item 样式
final VideoSpeedTipStyle videoSpeedTipStyle; // 长按倍速提示样式
final VideoEstimatedTimeBarStyle videoEstimatedTimeBarStyle;
final VideoDefinitionItemStyle videoDefinitionItemStyle; // 清晰度 item 样式 final VideoDefinitionItemStyle videoDefinitionItemStyle; // 清晰度 item 样式
final VideoDefinitionButtonStyle videoDefinitionButtonStyle; // 清晰度按钮样式 final VideoDefinitionButtonStyle videoDefinitionButtonStyle; // 清晰度按钮样式
final VideoBrightnessStyle videoBrightnessStyle; // 屏幕亮度样式 final VideoBrightnessStyle videoBrightnessStyle; // 屏幕亮度样式
......
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class VideoEstimatedTimeBarStyle {
final AlignmentGeometry alignment;
final Decoration decoration;
final EdgeInsetsGeometry padding;
final TextStyle textStyle;
VideoEstimatedTimeBarStyle({
this.alignment = Alignment.center,
this.decoration = const BoxDecoration(
color: Color(0x7F000000),
borderRadius: BorderRadius.all(Radius.circular(4.0)),
),
this.padding = const EdgeInsets.all(8.0),
this.textStyle = const TextStyle(color: Colors.white),
});
}
class VideoEstimatedTimeBar extends StatefulWidget { class VideoEstimatedTimeBar extends StatefulWidget {
const VideoEstimatedTimeBar({super.key, required this.notifier}); VideoEstimatedTimeBar({
super.key,
required this.notifier,
VideoEstimatedTimeBarStyle? videoEstimatedTimeBarStyle,
}) : videoEstimatedTimeBarStyle =
videoEstimatedTimeBarStyle ?? VideoEstimatedTimeBarStyle();
final EstimatedTimeNotifier notifier; final EstimatedTimeNotifier notifier;
final VideoEstimatedTimeBarStyle videoEstimatedTimeBarStyle;
@override @override
State<VideoEstimatedTimeBar> createState() => _VideoEstimatedTimeBarState(); State<VideoEstimatedTimeBar> createState() => _VideoEstimatedTimeBarState();
...@@ -12,6 +35,9 @@ class VideoEstimatedTimeBar extends StatefulWidget { ...@@ -12,6 +35,9 @@ class VideoEstimatedTimeBar extends StatefulWidget {
class _VideoEstimatedTimeBarState extends State<VideoEstimatedTimeBar> { class _VideoEstimatedTimeBarState extends State<VideoEstimatedTimeBar> {
EstimatedTimeNotifier get notifier => widget.notifier; EstimatedTimeNotifier get notifier => widget.notifier;
VideoEstimatedTimeBarStyle get videoEstimatedTimeBarStyle =>
widget.videoEstimatedTimeBarStyle;
String _position = '--:--'; String _position = '--:--';
String _duration = '--:--'; String _duration = '--:--';
bool _hidden = true; bool _hidden = true;
...@@ -27,13 +53,10 @@ class _VideoEstimatedTimeBarState extends State<VideoEstimatedTimeBar> { ...@@ -27,13 +53,10 @@ class _VideoEstimatedTimeBarState extends State<VideoEstimatedTimeBar> {
return Offstage( return Offstage(
offstage: _hidden, offstage: _hidden,
child: Align( child: Align(
alignment: Alignment.center, alignment: videoEstimatedTimeBarStyle.alignment,
child: Container( child: Container(
decoration: BoxDecoration( decoration: videoEstimatedTimeBarStyle.decoration,
color: Colors.black.withOpacity(0.5), padding: videoEstimatedTimeBarStyle.padding,
borderRadius: const BorderRadius.all(Radius.circular(6.0)),
),
padding: const EdgeInsets.all(8.0),
child: Text( child: Text(
'$_position / $_duration', '$_position / $_duration',
style: const TextStyle( style: const TextStyle(
...@@ -77,7 +100,6 @@ class EstimatedTimeNotifier with ChangeNotifier { ...@@ -77,7 +100,6 @@ class EstimatedTimeNotifier with ChangeNotifier {
bool get isEnd => _isEnd; bool get isEnd => _isEnd;
void update({required Duration position, required Duration duration}) { void update({required Duration position, required Duration duration}) {
_position = position; _position = position;
_duration = duration; _duration = duration;
......
import 'package:flutter/material.dart';
import 'package:gz_video_player/video_speed.dart';
class VideoSpeedTip extends StatelessWidget {
VideoSpeedTip({
super.key,
VideoSpeedTipStyle? videoSpeedTipStyle,
this.speed = '1.0X',
this.hidden = true,
}) : videoSpeedTipStyle = videoSpeedTipStyle ?? VideoSpeedTipStyle();
final VideoSpeedTipStyle videoSpeedTipStyle;
final String speed;
final bool hidden;
@override
Widget build(BuildContext context) {
return Offstage(
offstage: hidden,
child: Align(
alignment: videoSpeedTipStyle.alignment,
child: Container(
width: videoSpeedTipStyle.size.width,
height: videoSpeedTipStyle.size.height,
decoration: videoSpeedTipStyle.decoration,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
videoSpeedTipStyle.icon,
Padding(
padding: videoSpeedTipStyle.middlePadding,
child: Text(
speed,
style: videoSpeedTipStyle.speedTextStyle,
),
),
Text(
videoSpeedTipStyle.describe,
style: videoSpeedTipStyle.describeTextStyle,
),
],
),
),
),
);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论