基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
player panel init
Predidit007d5e14f553
diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dartindex afdb8868..92071b6b 100644--- a/lib/pages/player/player_controller.dart+++ b/lib/pages/player/player_controller.dart@@ -1,6 +1,7 @@import 'dart:io';import 'package:kazumi/bean/dialog/dialog_helper.dart';import 'package:media_kit/media_kit.dart';+import 'package:flutter/material.dart';import 'package:media_kit_video/media_kit_video.dart';import 'package:kazumi/modules/danmaku/danmaku_module.dart';import 'package:mobx/mobx.dart';@@ -19,21 +20,24 @@ part 'player_controller.g.dart';class PlayerController = _PlayerController with _$PlayerController;abstract class _PlayerController with Store {+ final VideoPageController videoPageController =+ Modular.get<VideoPageController>();@observablebool loading = true;-+ // 视频地址String videoUrl = '';- // dandanPlay弹幕ID+ // DanDanPlay 弹幕IDint bangumiID = 0;+ // 播放器实体late Player mediaPlayer;late VideoController videoController;+ // 弹幕控制器late DanmakuController danmakuController;- final VideoPageController videoPageController =- Modular.get<VideoPageController>();@observableMap<int, List<Danmaku>> danDanmakus = {};+ // 播放器状态@observablebool playing = false;@observable@@ -68,12 +72,36 @@ abstract class _PlayerController with Store {@observabledouble playerSpeed = 1.0;+ // 播放器界面控制+ @observable+ bool lockPanel = false;+ @observable+ bool showVideoController = false;+ @observable+ bool showSeekTime = false;+ @observable+ bool showBrightness = false;+ @observable+ bool showVolume = false;+ @observable+ bool showPlaySpeed = false;+ @observable+ bool brightnessSeeking = false;+ @observable+ bool volumeSeeking = false;+++ // 过渡动画+ AnimationController? animationController;+ late Animation<Offset> bottomOffsetAnimation;+ late Animation<Offset> topOffsetAnimation;+ late Animation<Offset> leftOffsetAnimation;+Box setting = GStorage.setting;bool hAenable = true;late String hardwareDecoder;bool lowMemoryMode = false;bool autoPlay = true;-int forwardTime = 80;Future<void> init(String url, {int offset = 0}) async {@@ -116,7 +144,8 @@ abstract class _PlayerController with Store {autoPlay = setting.get(SettingBoxKey.autoPlay, defaultValue: true);lowMemoryMode =setting.get(SettingBoxKey.lowMemoryMode, defaultValue: false);- KazumiLogger().log(Level.info, 'media_kit decoder: 硬件解码: $hAenable 解码器: $hardwareDecoder');+ KazumiLogger().log(+ Level.info, 'media_kit decoder: 硬件解码: $hAenable 解码器: $hardwareDecoder');if (videoPageController.currentPlugin.userAgent == '') {userAgent = Utils.getRandomUA();} else {diff --git a/lib/pages/player/player_controller.g.dart b/lib/pages/player/player_controller.g.dartindex 74d56850..d6ba0ac0 100644--- a/lib/pages/player/player_controller.g.dart+++ b/lib/pages/player/player_controller.g.dart@@ -217,6 +217,134 @@ mixin _$PlayerController on _PlayerController, Store {});}+ late final _$lockPanelAtom =+ Atom(name: '_PlayerController.lockPanel', context: context);++ @override+ bool get lockPanel {+ _$lockPanelAtom.reportRead();+ return super.lockPanel;+ }++ @override+ set lockPanel(bool value) {+ _$lockPanelAtom.reportWrite(value, super.lockPanel, () {+ super.lockPanel = value;+ });+ }++ late final _$showVideoControllerAtom =+ Atom(name: '_PlayerController.showVideoController', context: context);++ @override+ bool get showVideoController {+ _$showVideoControllerAtom.reportRead();+ return super.showVideoController;+ }++ @override+ set showVideoController(bool value) {+ _$showVideoControllerAtom.reportWrite(value, super.showVideoController, () {+ super.showVideoController = value;+ });+ }++ late final _$showSeekTimeAtom =+ Atom(name: '_PlayerController.showSeekTime', context: context);++ @override+ bool get showSeekTime {+ _$showSeekTimeAtom.reportRead();+ return super.showSeekTime;+ }++ @override+ set showSeekTime(bool value) {+ _$showSeekTimeAtom.reportWrite(value, super.showSeekTime, () {+ super.showSeekTime = value;+ });+ }++ late final _$showBrightnessAtom =+ Atom(name: '_PlayerController.showBrightness', context: context);++ @override+ bool get showBrightness {+ _$showBrightnessAtom.reportRead();+ return super.showBrightness;+ }++ @override+ set showBrightness(bool value) {+ _$showBrightnessAtom.reportWrite(value, super.showBrightness, () {+ super.showBrightness = value;+ });+ }++ late final _$showVolumeAtom =+ Atom(name: '_PlayerController.showVolume', context: context);++ @override+ bool get showVolume {+ _$showVolumeAtom.reportRead();+ return super.showVolume;+ }++ @override+ set showVolume(bool value) {+ _$showVolumeAtom.reportWrite(value, super.showVolume, () {+ super.showVolume = value;+ });+ }++ late final _$showPlaySpeedAtom =+ Atom(name: '_PlayerController.showPlaySpeed', context: context);++ @override+ bool get showPlaySpeed {+ _$showPlaySpeedAtom.reportRead();+ return super.showPlaySpeed;+ }++ @override+ set showPlaySpeed(bool value) {+ _$showPlaySpeedAtom.reportWrite(value, super.showPlaySpeed, () {+ super.showPlaySpeed = value;+ });+ }++ late final _$brightnessSeekingAtom =+ Atom(name: '_PlayerController.brightnessSeeking', context: context);++ @override+ bool get brightnessSeeking {+ _$brightnessSeekingAtom.reportRead();+ return super.brightnessSeeking;+ }++ @override+ set brightnessSeeking(bool value) {+ _$brightnessSeekingAtom.reportWrite(value, super.brightnessSeeking, () {+ super.brightnessSeeking = value;+ });+ }++ late final _$volumeSeekingAtom =+ Atom(name: '_PlayerController.volumeSeeking', context: context);++ @override+ bool get volumeSeeking {+ _$volumeSeekingAtom.reportRead();+ return super.volumeSeeking;+ }++ @override+ set volumeSeeking(bool value) {+ _$volumeSeekingAtom.reportWrite(value, super.volumeSeeking, () {+ super.volumeSeeking = value;+ });+ }+@overrideString toString() {return '''@@ -232,7 +360,15 @@ danmakuOn: ${danmakuOn},aspectRatioType: ${aspectRatioType},volume: ${volume},brightness: ${brightness},-playerSpeed: ${playerSpeed}+playerSpeed: ${playerSpeed},+lockPanel: ${lockPanel},+showVideoController: ${showVideoController},+showSeekTime: ${showSeekTime},+showBrightness: ${showBrightness},+showVolume: ${showVolume},+showPlaySpeed: ${showPlaySpeed},+brightnessSeeking: ${brightnessSeeking},+volumeSeeking: ${volumeSeeking}''';}}diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dartindex fe6b6c53..8d031f9e 100644--- a/lib/pages/player/player_item.dart+++ b/lib/pages/player/player_item.dart@@ -1,6 +1,7 @@import 'dart:async';import 'dart:io';import 'package:flutter/foundation.dart';+import 'package:kazumi/pages/player/player_item_panel.dart';import 'package:kazumi/utils/logger.dart';import 'package:kazumi/utils/remote.dart';import 'package:kazumi/utils/utils.dart';@@ -32,7 +33,6 @@ import 'package:kazumi/bean/appbar/drag_to_move_bar.dart' as dtb;import 'package:kazumi/pages/settings/danmaku/danmaku_settings_window.dart';import 'package:kazumi/utils/constants.dart';import 'package:kazumi/pages/player/episode_comments_sheet.dart';-import 'package:saver_gallery/saver_gallery.dart';import 'package:mobx/mobx.dart' as mobx;import 'package:kazumi/bean/widget/collect_button.dart';@@ -78,16 +78,6 @@ class _PlayerItemState extends State<PlayerItem>late bool webDavEnable;late bool haEnable;- // 界面管理- bool showVideoController = false;- bool showSeekTime = false;- bool showBrightness = false;- bool showVolume = false;- bool showPlaySpeed = false;- bool brightnessSeeking = false;- bool volumeSeeking = false;- bool lockPanel = false;-// 弹幕final _danmuKey = GlobalKey();late bool _border;@@ -105,12 +95,6 @@ class _PlayerItemState extends State<PlayerItem>late bool _danmakuDanDanSource;late int _danmakuFontWeight;- // 过渡动画- late AnimationController _animationController;- late Animation<Offset> _bottomOffsetAnimation;- late Animation<Offset> _topOffsetAnimation;- late Animation<Offset> _leftOffsetAnimation;-Timer? hideTimer;Timer? playerTimer;Timer? mouseScrollerTimer;@@ -134,27 +118,23 @@ class _PlayerItemState extends State<PlayerItem>}void displayVideoController() {- _animationController.forward();+ playerController.animationController?.forward();hideTimer?.cancel();startHideTimer();- setState(() {- showVideoController = true;- });+ playerController.showVideoController = true;}void hideVideoController() {- _animationController.reverse();+ playerController.animationController?.reverse();hideTimer?.cancel();- setState(() {- showVideoController = false;- });+ playerController.showVideoController = false;}void _handleTap() {if (Utils.isDesktop()) {playerController.playOrPause();} else {- if (showVideoController) {+ if (playerController.showVideoController) {hideVideoController();} else {displayVideoController();@@ -166,12 +146,12 @@ class _PlayerItemState extends State<PlayerItem>if (Utils.isDesktop()) {_handleFullscreen();} else {- if (showVideoController) {+ if (playerController.showVideoController) {hideVideoController();} else {displayVideoController();}- if (lockPanel) {+ if (playerController.lockPanel) {return;}playerController.playOrPause();@@ -179,36 +159,28 @@ class _PlayerItemState extends State<PlayerItem>}void _handleHove() {- if (!showVideoController) {+ if (!playerController.showVideoController) {displayVideoController();}}void _handleMouseScroller() {- setState(() {- showVolume = true;- });+ playerController.showVolume = true;mouseScrollerTimer?.cancel();mouseScrollerTimer = Timer(const Duration(seconds: 2), () {if (mounted) {- setState(() {- showVolume = false;- });+ playerController.showVolume = false;}mouseScrollerTimer = null;});}void _handleKeyChangingVolume() {- setState(() {- showVolume = true;- });+ playerController.showVolume = true;hideVolumeUITimer?.cancel();hideVolumeUITimer = Timer(const Duration(seconds: 2), () {if (mounted) {- setState(() {- showVolume = false;- });+ playerController.showVolume = false;}hideVolumeUITimer = null;});@@ -299,7 +271,7 @@ class _PlayerItemState extends State<PlayerItem>});}// 音量相关- if (!volumeSeeking) {+ if (!playerController.volumeSeeking) {if (Utils.isDesktop()) {playerController.volume = playerController.mediaPlayer.state.volume;} else {@@ -313,7 +285,7 @@ class _PlayerItemState extends State<PlayerItem>if (!Platform.isWindows &&!Platform.isMacOS &&!Platform.isLinux &&- !brightnessSeeking) {+ !playerController.brightnessSeeking) {ScreenBrightnessPlatform.instance.application.then((value) {playerController.brightness = value;});@@ -351,9 +323,7 @@ class _PlayerItemState extends State<PlayerItem>void _handleFullscreenChange(BuildContext context) async {if (videoPageController.isFullscreen && !Utils.isTablet()) {- setState(() {- lockPanel = false;- });+ playerController.lockPanel = false;}danmakuController.clear();if (webDavEnable) {@@ -660,24 +630,6 @@ class _PlayerItemState extends State<PlayerItem>} catch (_) {}}- Future<void> _handleScreenshot() async {- KazumiDialog.showToast(message: '截图中...');-- try {- Uint8List? screenshot =- await playerController.mediaPlayer.screenshot(format: 'image/png');- final result = await SaverGallery.saveImage(screenshot!,- fileName: DateTime.timestamp().toString(), skipIfExists: false);- if (result.isSuccess) {- KazumiDialog.showToast(message: '截图保存到相簿成功');- } else {- KazumiDialog.showToast(message: '截图保存失败:${result.errorMessage}');- }- } catch (e) {- KazumiDialog.showToast(message: '截图失败:$e');- }- }-@overridevoid onWindowRestore() {danmakuController.onClear();@@ -698,29 +650,29 @@ class _PlayerItemState extends State<PlayerItem>category: AudioSessionCategory.playback);}WidgetsBinding.instance.addObserver(this);- _animationController = AnimationController(+ playerController.animationController = AnimationController(duration: const Duration(milliseconds: 300),vsync: this,);- _topOffsetAnimation = Tween<Offset>(+ playerController.topOffsetAnimation = Tween<Offset>(begin: const Offset(0.0, -1.0),end: const Offset(0.0, 0.0),).animate(CurvedAnimation(- parent: _animationController,+ parent: playerController.animationController!,curve: Curves.easeInOut,));- _bottomOffsetAnimation = Tween<Offset>(+ playerController.bottomOffsetAnimation = Tween<Offset>(begin: const Offset(0.0, 1.0),end: const Offset(0.0, 0.0),).animate(CurvedAnimation(- parent: _animationController,+ parent: playerController.animationController!,curve: Curves.easeInOut,));- _leftOffsetAnimation = Tween<Offset>(+ playerController.leftOffsetAnimation = Tween<Offset>(begin: const Offset(1.0, 0.0),end: const Offset(0.0, 0.0),).animate(CurvedAnimation(- parent: _animationController,+ parent: playerController.animationController!,curve: Curves.easeInOut,));webDavEnable = setting.get(SettingBoxKey.webDavEnable, defaultValue: false);@@ -763,7 +715,18 @@ class _PlayerItemState extends State<PlayerItem>WidgetsBinding.instance.removeObserver(this);windowManager.removeListener(this);playerTimer?.cancel();- _animationController.dispose();+ playerController.animationController?.dispose();+ playerController.animationController = null;+ // Reset player panel state+ playerController.lockPanel = false;+ playerController.showVideoController = false;+ playerController.showSeekTime = false;+ playerController.showBrightness = false;+ playerController.showVolume = false;+ playerController.showPlaySpeed = false;+ playerController.brightnessSeeking = false;+ playerController.volumeSeeking = false;+ // Reset danmaku stateinfoController.episodeCommentsList.clear();infoController.episodeInfo.reset();super.dispose();@@ -779,7 +742,8 @@ class _PlayerItemState extends State<PlayerItem>child: Container(color: Colors.black,child: MouseRegion(- cursor: (videoPageController.isFullscreen && !showVideoController)+ cursor: (videoPageController.isFullscreen &&+ !playerController.showVideoController)? SystemMouseCursors.none: SystemMouseCursors.basic,onHover: (_) {@@ -892,9 +856,7 @@ class _PlayerItemState extends State<PlayerItem>if (event.logicalKey ==LogicalKeyboardKey.arrowRight) {if (playerController.playerSpeed < 2.0) {- setState(() {- showPlaySpeed = true;- });+ playerController.showPlaySpeed = true;_setPlaybackSpeed(2.0);}}@@ -902,10 +864,8 @@ class _PlayerItemState extends State<PlayerItem>// 右方向键抬起if (event.logicalKey ==LogicalKeyboardKey.arrowRight) {- if (showPlaySpeed) {- setState(() {- showPlaySpeed = false;- });+ if (playerController.showPlaySpeed) {+ playerController.showPlaySpeed = false;_setPlaybackSpeed(lastPlayerSpeed);} else {try {@@ -941,21 +901,21 @@ class _PlayerItemState extends State<PlayerItem>_handleDoubleTap();},onLongPressStart: (_) {- if (lockPanel) {+ if (playerController.lockPanel) {return;}setState(() {- showPlaySpeed = true;+ playerController.showPlaySpeed = true;});lastPlayerSpeed = playerController.playerSpeed;_setPlaybackSpeed(2.0);},onLongPressEnd: (_) {- if (lockPanel) {+ if (playerController.lockPanel) {return;}setState(() {- showPlaySpeed = false;+ playerController.showPlaySpeed = false;});_setPlaybackSpeed(lastPlayerSpeed);},@@ -965,74 +925,18 @@ class _PlayerItemState extends State<PlayerItem>height: double.infinity,),),-- //顶部渐变区域- AnimatedPositioned(- duration: const Duration(seconds: 1),- top: 0,- left: 0,- right: 0,- child: Visibility(- visible: !lockPanel,- child: SlideTransition(- position: _topOffsetAnimation,- child: Container(- height: 50,- decoration: BoxDecoration(- gradient: LinearGradient(- begin: Alignment.topCenter,- end: Alignment.bottomCenter,- colors: [- Colors.black.withOpacity(0.9),- Colors.transparent,- ],- ),- ),- ),- ),- ),- ),-- //底部渐变区域- AnimatedPositioned(- duration: const Duration(seconds: 1),- bottom: 0,- left: 0,- right: 0,- child: Visibility(- visible: !lockPanel,- child: SlideTransition(- position: _bottomOffsetAnimation,- child: Container(- height: 50,- decoration: BoxDecoration(- gradient: LinearGradient(- begin: Alignment.topCenter,- end: Alignment.bottomCenter,- colors: [- Colors.transparent,- Colors.black.withOpacity(0.9),- ],- ),- ),- ),- ),- ),- ),-+ const PlayerItemPanel(),// 播放器手势控制Positioned.fill(left: 16,top: 25,right: 15,bottom: 15,- child: (Utils.isDesktop() || lockPanel)+ child: (Utils.isDesktop() || playerController.lockPanel)? Container(): GestureDetector(onHorizontalDragUpdate:(DragUpdateDetails details) {- setState(() {- showSeekTime = true;- });+ playerController.showSeekTime = true;playerTimer?.cancel();playerController.pause();final double scale =@@ -1048,9 +952,7 @@ class _PlayerItemState extends State<PlayerItem>playerController.seek(playerController.currentPosition);playerTimer = getPlayerTimer();- setState(() {- showSeekTime = false;- });+ playerController.showSeekTime = false;}, onVerticalDragUpdate:(DragUpdateDetails details) async {final double totalWidth =@@ -1068,10 +970,8 @@ class _PlayerItemState extends State<PlayerItem>}if (tapPosition < sectionWidth) {// 左边区域- brightnessSeeking = true;- setState(() {- showBrightness = true;- });+ playerController.brightnessSeeking = true;+ playerController.showBrightness = true;final double level = (totalHeight) * 2;final double brightness =playerController.brightness -@@ -1082,10 +982,8 @@ class _PlayerItemState extends State<PlayerItem>playerController.brightness = result;} else {// 右边区域- volumeSeeking = true;- setState(() {- showVolume = true;- });+ playerController.volumeSeeking = true;+ playerController.showVolume = true;final double level = (totalHeight) * 0.03;final double volume =playerController.volume - delta / level;@@ -1095,141 +993,21 @@ class _PlayerItemState extends State<PlayerItem>playerController.volume = result;}}, onVerticalDragEnd: (DragEndDetails details) {- if (volumeSeeking) {- volumeSeeking = false;+ if (playerController.volumeSeeking) {+ playerController.volumeSeeking = false;Future.delayed(const Duration(seconds: 1),() {FlutterVolumeController.updateShowSystemUI(true);});}- if (brightnessSeeking) {- brightnessSeeking = false;+ if (playerController.brightnessSeeking) {+ playerController.brightnessSeeking = false;}- setState(() {- showVolume = false;- showBrightness = false;- });+ playerController.showVolume = false;+ playerController.showBrightness = false;})),- // 顶部进度条- Positioned(- top: 25,- child: showSeekTime- ? Wrap(- alignment: WrapAlignment.center,- children: <Widget>[- Container(- padding: const EdgeInsets.all(8.0),- decoration: BoxDecoration(- color: Colors.black.withOpacity(0.5),- borderRadius:- BorderRadius.circular(8.0), // 圆角- ),- child: Text(- playerController.currentPosition- .compareTo(playerController- .mediaPlayer- .state- .position) >- 0- ? '快进 ${playerController.currentPosition.inSeconds - playerController.mediaPlayer.state.position.inSeconds} 秒'- : '快退 ${playerController.mediaPlayer.state.position.inSeconds - playerController.currentPosition.inSeconds} 秒',- style: const TextStyle(- color: Colors.white,- ),- ),- ),- ],- )- : Container()),- // 顶部播放速度条- Positioned(- top: 25,- child: showPlaySpeed- ? Wrap(- alignment: WrapAlignment.center,- children: <Widget>[- Container(- padding: const EdgeInsets.all(8.0),- decoration: BoxDecoration(- color: Colors.black.withOpacity(0.5),- borderRadius:- BorderRadius.circular(8.0), // 圆角- ),- child: const Row(- children: <Widget>[- Icon(Icons.fast_forward,- color: Colors.white),- Text(- ' 倍速播放',- style: TextStyle(- color: Colors.white,- ),- ),- ],- ),- ),- ],- )- : Container()),- // 亮度条- Positioned(- top: 25,- child: showBrightness- ? Wrap(- alignment: WrapAlignment.center,- children: <Widget>[- Container(- padding: const EdgeInsets.all(8.0),- decoration: BoxDecoration(- color: Colors.black.withOpacity(0.5),- borderRadius:- BorderRadius.circular(8.0), // 圆角- ),- child: Row(- children: <Widget>[- const Icon(Icons.brightness_7,- color: Colors.white),- Text(- ' ${(playerController.brightness * 100).toInt()} %',- style: const TextStyle(- color: Colors.white,- ),- ),- ],- )),- ],- )- : Container()),- // 音量条- Positioned(- top: 25,- child: showVolume- ? Wrap(- alignment: WrapAlignment.center,- children: <Widget>[- Container(- padding: const EdgeInsets.all(8.0),- decoration: BoxDecoration(- color: Colors.black.withOpacity(0.5),- borderRadius:- BorderRadius.circular(8.0), // 圆角- ),- child: Row(- children: <Widget>[- const Icon(Icons.volume_down,- color: Colors.white),- Text(- ' ${playerController.volume.toInt()}%',- style: const TextStyle(- color: Colors.white,- ),- ),- ],- )),- ],- )- : Container()),+// 弹幕面板Positioned(top: 0,@@ -1260,55 +1038,15 @@ class _PlayerItemState extends State<PlayerItem>),),- // 右侧锁定按钮- (Utils.isDesktop() || !videoPageController.isFullscreen)- ? Container()- : Positioned(- right: 0,- top: 0,- bottom: 0,- child: SlideTransition(- position: _leftOffsetAnimation,- child: Column(children: [- const Spacer(),- (lockPanel)- ? Container()- : IconButton(- icon: const Icon(- Icons.photo_camera_outlined,- color: Colors.white,- ),- onPressed: () {- _handleScreenshot();- },- ),- IconButton(- icon: Icon(- lockPanel- ? Icons.lock_outline- : Icons.lock_open,- color: Colors.white,- ),- onPressed: () {- setState(() {- lockPanel = !lockPanel;- });- },- ),- const Spacer(),- ]),- ),- ),-// 自定义顶部组件Positioned(top: 0,left: 0,right: 0,child: Visibility(- visible: !lockPanel,+ visible: !playerController.lockPanel,child: SlideTransition(- position: _topOffsetAnimation,+ position: playerController.topOffsetAnimation,child: Row(children: [IconButton(@@ -1532,9 +1270,9 @@ class _PlayerItemState extends State<PlayerItem>left: 0,right: 0,child: Visibility(- visible: !lockPanel,+ visible: !playerController.lockPanel,child: SlideTransition(- position: _bottomOffsetAnimation,+ position: playerController.bottomOffsetAnimation,child: Row(children: [IconButton(@@ -1594,9 +1332,7 @@ class _PlayerItemState extends State<PlayerItem>playerTimer?.cancel();playerController.pause();hideTimer?.cancel();- setState(() {- showVideoController = true;- });+ playerController.showVideoController = true;},onDragUpdate: (details) => {playerController.currentPosition =@@ -1737,10 +1473,8 @@ class _PlayerItemState extends State<PlayerItem>void startHideTimer() {hideTimer = Timer(const Duration(seconds: 4), () {if (mounted) {- setState(() {- showVideoController = false;- });- _animationController.reverse();+ playerController.showVideoController = false;+ playerController.animationController?.reverse();}hideTimer = null;});diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dartnew file mode 100644index 00000000..b52a2118--- /dev/null+++ b/lib/pages/player/player_item_panel.dart@@ -0,0 +1,257 @@+import 'package:flutter/material.dart';+import 'package:flutter_mobx/flutter_mobx.dart';+import 'package:flutter_modular/flutter_modular.dart';+import 'package:kazumi/utils/utils.dart';+import 'package:kazumi/pages/video/video_controller.dart';+import 'package:kazumi/bean/dialog/dialog_helper.dart';+import 'package:kazumi/pages/player/player_controller.dart';+import 'package:saver_gallery/saver_gallery.dart';+import 'package:flutter/services.dart';++class PlayerItemPanel extends StatefulWidget {+ const PlayerItemPanel({+ super.key,+ });++ @override+ State<PlayerItemPanel> createState() => _PlayerItemPanelState();+}++class _PlayerItemPanelState extends State<PlayerItemPanel> {+ final VideoPageController videoPageController =+ Modular.get<VideoPageController>();+ final PlayerController playerController = Modular.get<PlayerController>();++ Future<void> _handleScreenshot() async {+ KazumiDialog.showToast(message: '截图中...');++ try {+ Uint8List? screenshot =+ await playerController.mediaPlayer.screenshot(format: 'image/png');+ final result = await SaverGallery.saveImage(screenshot!,+ fileName: DateTime.timestamp().toString(), skipIfExists: false);+ if (result.isSuccess) {+ KazumiDialog.showToast(message: '截图保存到相簿成功');+ } else {+ KazumiDialog.showToast(message: '截图保存失败:${result.errorMessage}');+ }+ } catch (e) {+ KazumiDialog.showToast(message: '截图失败:$e');+ }+ }++ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: Observer(builder: (context) {+ return Stack(+ children: [+ //顶部渐变区域+ AnimatedPositioned(+ duration: const Duration(seconds: 1),+ top: 0,+ left: 0,+ right: 0,+ child: Visibility(+ visible: !playerController.lockPanel,+ child: SlideTransition(+ position: playerController.topOffsetAnimation,+ child: Container(+ height: 50,+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [+ Colors.black.withOpacity(0.9),+ Colors.transparent,+ ],+ ),+ ),+ ),+ ),+ ),+ ),++ //底部渐变区域+ AnimatedPositioned(+ duration: const Duration(seconds: 1),+ bottom: 0,+ left: 0,+ right: 0,+ child: Visibility(+ visible: !playerController.lockPanel,+ child: SlideTransition(+ position: playerController.bottomOffsetAnimation,+ child: Container(+ height: 50,+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [+ Colors.transparent,+ Colors.black.withOpacity(0.9),+ ],+ ),+ ),+ ),+ ),+ ),+ ),+ // 顶部进度条+ Positioned(+ top: 25,+ child: playerController.showSeekTime+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding: const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black.withOpacity(0.5),+ borderRadius: BorderRadius.circular(8.0), // 圆角+ ),+ child: Text(+ playerController.currentPosition.compareTo(+ playerController+ .mediaPlayer.state.position) >+ 0+ ? '快进 ${playerController.currentPosition.inSeconds - playerController.mediaPlayer.state.position.inSeconds} 秒'+ : '快退 ${playerController.mediaPlayer.state.position.inSeconds - playerController.currentPosition.inSeconds} 秒',+ style: const TextStyle(+ color: Colors.white,+ ),+ ),+ ),+ ],+ )+ : Container()),+ // 顶部播放速度条+ Positioned(+ top: 25,+ child: playerController.showPlaySpeed+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding: const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black.withOpacity(0.5),+ borderRadius: BorderRadius.circular(8.0), // 圆角+ ),+ child: const Row(+ children: <Widget>[+ Icon(Icons.fast_forward, color: Colors.white),+ Text(+ ' 倍速播放',+ style: TextStyle(+ color: Colors.white,+ ),+ ),+ ],+ ),+ ),+ ],+ )+ : Container()),+ // 亮度条+ Positioned(+ top: 25,+ child: playerController.showBrightness+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding: const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black.withOpacity(0.5),+ borderRadius: BorderRadius.circular(8.0), // 圆角+ ),+ child: Row(+ children: <Widget>[+ const Icon(Icons.brightness_7,+ color: Colors.white),+ Text(+ ' ${(playerController.brightness * 100).toInt()} %',+ style: const TextStyle(+ color: Colors.white,+ ),+ ),+ ],+ )),+ ],+ )+ : Container()),+ // 音量条+ Positioned(+ top: 25,+ child: playerController.showVolume+ ? Wrap(+ alignment: WrapAlignment.center,+ children: <Widget>[+ Container(+ padding: const EdgeInsets.all(8.0),+ decoration: BoxDecoration(+ color: Colors.black.withOpacity(0.5),+ borderRadius: BorderRadius.circular(8.0), // 圆角+ ),+ child: Row(+ children: <Widget>[+ const Icon(Icons.volume_down,+ color: Colors.white),+ Text(+ ' ${playerController.volume.toInt()}%',+ style: const TextStyle(+ color: Colors.white,+ ),+ ),+ ],+ )),+ ],+ )+ : Container()),+ // 右侧锁定按钮+ (Utils.isDesktop() || !videoPageController.isFullscreen)+ ? Container()+ : Positioned(+ right: 0,+ top: 0,+ bottom: 0,+ child: SlideTransition(+ position: playerController.leftOffsetAnimation,+ child: Column(children: [+ const Spacer(),+ (playerController.lockPanel)+ ? Container()+ : IconButton(+ icon: const Icon(+ Icons.photo_camera_outlined,+ color: Colors.white,+ ),+ onPressed: () {+ _handleScreenshot();+ },+ ),+ IconButton(+ icon: Icon(+ playerController.lockPanel+ ? Icons.lock_outline+ : Icons.lock_open,+ color: Colors.white,+ ),+ onPressed: () {+ playerController.lockPanel =+ !playerController.lockPanel;+ },+ ),+ const Spacer(),+ ]),+ ),+ ),+ ],+ );+ }),+ );+ }+}