-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
// Flutter imports: | ||
import 'package:flutter/material.dart' as material; | ||
|
||
// Package imports: | ||
import 'package:fluent_ui/fluent_ui.dart'; | ||
import 'package:media_kit_video/media_kit_video.dart'; | ||
import 'package:pasteboard/pasteboard.dart'; | ||
|
||
// Project imports: | ||
import '../../components/app/app_infobar.dart'; | ||
import '../../tools/file_tool.dart'; | ||
|
||
class BtcVideo extends StatefulWidget { | ||
/// controller | ||
final VideoController controller; | ||
|
||
/// 构造函数 | ||
const BtcVideo(this.controller, {super.key}); | ||
|
||
@override | ||
State<BtcVideo> createState() => _BtcVideoState(); | ||
} | ||
|
||
class _BtcVideoState extends State<BtcVideo> | ||
with material.AutomaticKeepAliveClientMixin { | ||
/// 控制器 | ||
VideoController get controller => widget.controller; | ||
|
||
/// fileTool | ||
final BTFileTool fileTool = BTFileTool(); | ||
|
||
/// 当前播放速度 | ||
double speed = 1.0; | ||
|
||
/// 速度的flyout | ||
final FlyoutController speedFlyout = FlyoutController(); | ||
|
||
@override | ||
bool get wantKeepAlive => true; | ||
|
||
@override | ||
void dispose() { | ||
speedFlyout.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
/// 根据速度获取对应文本 | ||
String getSpeedLabel(double val) { | ||
if (val == 2.0) return '2.0倍速'; | ||
if (val == 1.5) return '1.5倍速'; | ||
if (val == 1.25) return '1.25倍速'; | ||
if (val == 1.0) return '1.0倍速'; | ||
return '${val.toStringAsFixed(2)}倍速'; | ||
} | ||
|
||
/// 显示速度flyout | ||
void showSpeedFlyout() { | ||
speedFlyout.showFlyout( | ||
barrierDismissible: true, | ||
dismissOnPointerMoveAway: true, | ||
dismissWithEsc: true, | ||
builder: (context) { | ||
return MenuFlyout(items: [ | ||
buildSpeedButton(2.0), | ||
buildSpeedButton(1.5), | ||
buildSpeedButton(1.25), | ||
buildSpeedButton(1.0), | ||
]); | ||
}, | ||
); | ||
} | ||
|
||
/// 构建速度按钮 | ||
MenuFlyoutItem buildSpeedButton(double value) { | ||
return MenuFlyoutItem( | ||
leading: value == speed ? const Icon(material.Icons.check) : null, | ||
text: Text(getSpeedLabel(value)), | ||
onPressed: () async { | ||
speed = value; | ||
setState(() {}); | ||
await controller.player.setRate(value); | ||
}, | ||
); | ||
} | ||
|
||
/// 控制栏的数据构建 | ||
MaterialDesktopVideoControlsThemeData buildControls() { | ||
var base = FluentTheme.of(context).accentColor; | ||
return MaterialDesktopVideoControlsThemeData( | ||
seekBarThumbColor: base.lighter, | ||
seekBarPositionColor: base.darker, | ||
bottomButtonBar: [ | ||
const MaterialDesktopPlayOrPauseButton(), | ||
const MaterialDesktopPositionIndicator(), | ||
const MaterialDesktopVolumeButton(), | ||
const Spacer(), | ||
IconButton( | ||
onPressed: () async { | ||
await controller.player.pause(); | ||
var res = await controller.player.screenshot(); | ||
if (res == null) { | ||
if (mounted) await BtInfobar.error(context, '截图失败'); | ||
await controller.player.play(); | ||
return; | ||
} | ||
var ts = DateTime.now().millisecondsSinceEpoch ~/ 1000; | ||
var imagePath = await fileTool.writeTempImage(res, ts.toString()); | ||
// 提前写个空白文件,以防粘贴把之前的文本带上 | ||
// todo 详见 https://github.com/MixinNetwork/flutter-plugins/issues/335 | ||
Pasteboard.writeText(''); | ||
var check = await Pasteboard.writeFiles([imagePath]); | ||
if (!check) { | ||
if (mounted) await BtInfobar.error(context, '截图失败'); | ||
await controller.player.play(); | ||
return; | ||
} | ||
if (mounted) await BtInfobar.success(context, '截图已复制到剪贴板'); | ||
await controller.player.play(); | ||
}, | ||
icon: const Icon(FluentIcons.camera, size: 24), | ||
), | ||
FlyoutTarget( | ||
controller: speedFlyout, | ||
child: IconButton( | ||
icon: const Icon(material.Icons.fast_forward, size: 24), | ||
onPressed: showSpeedFlyout, | ||
), | ||
), | ||
const MaterialDesktopFullscreenButton(), | ||
], | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
super.build(context); | ||
return MaterialDesktopVideoControlsTheme( | ||
normal: buildControls(), | ||
fullscreen: buildControls(), | ||
child: material.Scaffold(body: Video(controller: controller)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters