基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
refactor pc player panel
ErBW_s665374ba3b39
diff --git a/lib/bean/widget/collect_button.dart b/lib/bean/widget/collect_button.dartindex df58342b..04b60597 100644--- a/lib/bean/widget/collect_button.dart+++ b/lib/bean/widget/collect_button.dart@@ -65,33 +65,53 @@ class _CollectButtonState extends State<CollectButton> {@overrideWidget build(BuildContext context) {collectType = collectController.getCollectType(widget.bangumiItem);- return PopupMenuButton(- tooltip: '',- icon: Icon(- getIconByInt(collectType),- color: widget.color,- ),- itemBuilder: (context) {- return List.generate(- 6,- (i) => PopupMenuItem(- value: i,+ return MenuAnchor(+ builder:+ (BuildContext context, MenuController controller, Widget? child) {+ return IconButton(+ onPressed: () {+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();+ }+ },+ icon: Icon(+ getIconByInt(collectType),+ color: widget.color,+ ),+ );+ },+ menuChildren: List<MenuItemButton>.generate(+ 6,+ (int index) => MenuItemButton(+ onPressed: () {+ if (index != collectType && mounted) {+ collectController.addCollect(widget.bangumiItem, type: index);+ setState(() {});+ }+ },+ child: Padding(+ padding: const EdgeInsets.fromLTRB(0, 10, 10, 10),child: Row(mainAxisSize: MainAxisSize.min,children: [- Icon(getIconByInt(i)),- Text(' ${getTypeStringByInt(i)}'),+ Icon(getIconByInt(index),+ color: index == collectType+ ? Theme.of(context).colorScheme.primary+ : Colors.white),+ Text(+ ' ${getTypeStringByInt(index)}',+ style: TextStyle(+ color: index == collectType+ ? Theme.of(context).colorScheme.primary+ : Colors.white),+ ),],),),- );- },- onSelected: (value) {- if (value != collectType && mounted) {- collectController.addCollect(widget.bangumiItem, type: value);- setState(() {});- }- },+ ),+ ),);}}diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dartindex 971db5ee..41a975f2 100644--- a/lib/pages/player/player_item.dart+++ b/lib/pages/player/player_item.dart@@ -141,7 +141,7 @@ class _PlayerItemState extends State<PlayerItem>}}- void _handleHove() {+ void handleHove() {if (!playerController.showVideoController) {displayVideoController();}@@ -581,7 +581,7 @@ class _PlayerItemState extends State<PlayerItem>// workaround for android.// I don't know why, but android tap event will trigger onHover event.if (Utils.isDesktop()) {- _handleHove();+ handleHove();}},child: Listener(@@ -795,6 +795,8 @@ class _PlayerItemState extends State<PlayerItem>handleProgressBarDragStart: handleProgressBarDragStart,handleProgressBarDragEnd: handleProgressBarDragEnd,animationController: animationController!,+ keyboardFocus: widget.keyboardFocus,+ handleHove: handleHove,),// 播放器手势控制Positioned.fill(diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dartindex f77169a7..bd523ae9 100644--- a/lib/pages/player/player_item_panel.dart+++ b/lib/pages/player/player_item_panel.dart@@ -30,6 +30,8 @@ class PlayerItemPanel extends StatefulWidget {required this.handleProgressBarDragEnd,required this.animationController,required this.openMenu,+ required this.keyboardFocus,+ required this.handleHove,});final void Function(BuildContext) onBackPressed;@@ -40,7 +42,9 @@ class PlayerItemPanel extends StatefulWidget {final void Function() handleFullscreen;final void Function(ThumbDragDetails details) handleProgressBarDragStart;final void Function() handleProgressBarDragEnd;+ final void Function() handleHove;final AnimationController animationController;+ final FocusNode keyboardFocus;@overrideState<PlayerItemPanel> createState() => _PlayerItemPanelState();@@ -56,6 +60,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {Modular.get<VideoPageController>();final InfoController infoController = Modular.get<InfoController>();final PlayerController playerController = Modular.get<PlayerController>();+ final TextEditingController textController = TextEditingController();Future<void> _handleScreenshot() async {KazumiDialog.showToast(message: '截图中...');@@ -84,59 +89,80 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {}/// 发送弹幕 由于接口限制, 暂时未提交云端- void showShootDanmakuSheet() {- final TextEditingController textController = TextEditingController();- bool isSending = false;- KazumiDialog.show(builder: (context) {- return AlertDialog(- title: const Text('发送弹幕'),- content: StatefulBuilder(- builder: (BuildContext context, StateSetter setState) {- return TextField(- controller: textController,- );- }),- actions: [- TextButton(- onPressed: () => KazumiDialog.dismiss(),- child: Text(- '取消',- style: TextStyle(color: Theme.of(context).colorScheme.outline),+ void sendDanmaku() async {+ widget.keyboardFocus.requestFocus();+ if (playerController.danDanmakus.isEmpty) {+ KazumiDialog.showToast(+ message: '当前剧集不支持弹幕发送的说',+ );+ return;+ }+ final String msg = textController.text;+ if (msg.isEmpty) {+ KazumiDialog.showToast(message: '弹幕内容为空');+ return;+ } else if (msg.length > 100) {+ KazumiDialog.showToast(message: '弹幕内容过长');+ return;+ }+ // Todo 接口方限制++ KazumiDialog.showToast(message: '发送成功');+ playerController.danmakuController+ .addDanmaku(DanmakuContentItem(msg, selfSend: true));+ textController.clear();+ }++ Widget danmakuTextField() {+ return Container(+ constraints: const BoxConstraints(maxWidth: 500, maxHeight: 33),+ child: TextField(+ style: const TextStyle(fontSize: 15),+ controller: textController,+ textAlignVertical: TextAlignVertical.center,+ decoration: InputDecoration(+ enabled: playerController.danmakuOn,+ filled: true,+ fillColor: Colors.white30,+ floatingLabelBehavior: FloatingLabelBehavior.never,+ hintText: playerController.danmakuOn ? '发个友善的弹幕见证当下' : '已关闭弹幕',+ hintStyle: const TextStyle(fontSize: 15),+ alignLabelWithHint: true,+ contentPadding:+ const EdgeInsets.symmetric(vertical: 8, horizontal: 8),+ border: const OutlineInputBorder(+ borderSide: BorderSide.none,+ borderRadius: BorderRadius.all(Radius.circular(8)),+ ),+ suffixIcon: TextButton(+ onPressed: () {+ sendDanmaku();+ },+ style: TextButton.styleFrom(+ foregroundColor: playerController.danmakuOn+ ? Theme.of(context).colorScheme.onPrimaryContainer+ : Colors.white,+ backgroundColor: playerController.danmakuOn+ ? Theme.of(context).colorScheme.primaryContainer+ : Theme.of(context).disabledColor,+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.circular(8),+ ),),+ child: const Text('发送'),),- StatefulBuilder(- builder: (BuildContext context, StateSetter setState) {- return TextButton(- onPressed: isSending- ? null- : () async {- final String msg = textController.text;- if (msg.isEmpty) {- KazumiDialog.showToast(message: '弹幕内容为空');- return;- } else if (msg.length > 100) {- KazumiDialog.showToast(message: '弹幕内容过长');- return;- }- setState(() {- isSending = true; // 开始发送,更新状态- });- // Todo 接口方限制-- setState(() {- isSending = false; // 发送结束,更新状态- });- KazumiDialog.showToast(message: '发送成功');- playerController.danmakuController- .addDanmaku(DanmakuContentItem(msg, selfSend: true));- KazumiDialog.dismiss();- },- child: Text(isSending ? '发送中' : '发送'),- );- })- ],- );- });+ ),+ onChanged: (_) {+ widget.handleHove();+ },+ onSubmitted: (_) {+ sendDanmaku();+ },+ onTapOutside: (_) {+ widget.keyboardFocus.requestFocus(FocusNode());+ },+ ),+ );}void showVideoInfo() async {@@ -358,7 +384,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {child: SlideTransition(position: bottomOffsetAnimation,child: Container(- height: 50,+ height: 60,decoration: BoxDecoration(gradient: LinearGradient(begin: Alignment.topCenter,@@ -535,7 +561,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {children: [IconButton(color: Colors.white,- icon: const Icon(Icons.arrow_back),+ icon: const Icon(Icons.arrow_back_rounded),onPressed: () {widget.onBackPressed(context);},@@ -555,175 +581,64 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {const Expanded(child: dtb.DragToMoveArea(child: SizedBox(height: 40)),),- PopupMenuButton(- tooltip: '',- child: Text(- playerController.superResolutionType == 1- ? 'OFF'- : playerController.superResolutionType == 2- ? "Efficiency"- : "Quality",- style: const TextStyle(- color: Colors.white,- fontSize: 12,- fontWeight: FontWeight.bold)),- itemBuilder: (context) {- return const [- PopupMenuItem(- value: 1,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("OFF")],- ),- ),- PopupMenuItem(- value: 2,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("Efficiency")],- ),- ),- PopupMenuItem(- value: 3,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("Quality")],- ),- ),- ];- },- onSelected: (value) {- playerController.setShader(value);- },- ),- const SizedBox(- width: 20,- ),- PopupMenuButton(- tooltip: '',- child: Text(- playerController.aspectRatioType == 1- ? 'AUTO'- : playerController.aspectRatioType == 2- ? 'COVER'- : 'FILL',- style: const TextStyle(- color: Colors.white,- fontSize: 12,- fontWeight: FontWeight.bold)),- itemBuilder: (context) {- return const [- PopupMenuItem(- value: 1,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("AUTO")],- ),- ),- PopupMenuItem(- value: 2,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("COVER")],- ),- ),- PopupMenuItem(- value: 3,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("FILL")],- ),- ),- ];- },- onSelected: (value) {- playerController.aspectRatioType = value;- },- ),- TextButton(- style: ButtonStyle(- padding: WidgetStateProperty.all(EdgeInsets.zero),- ),- onPressed: () {- // 倍速播放- showSetSpeedSheet();- },- child: Text(- '${playerController.playerSpeed}X',- style: const TextStyle(- color: Colors.white,- fontSize: 12,- fontWeight: FontWeight.bold),- ),- ),+ forwardIcon(),// 追番CollectButton(bangumiItem: infoController.bangumiItem),- PopupMenuButton(- tooltip: '',- icon: const Icon(- Icons.more_vert,- color: Colors.white,- ),- itemBuilder: (context) {- return const [- PopupMenuItem(- value: 0,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("弹幕设置")],+ MenuAnchor(+ builder: (BuildContext context,+ MenuController controller, Widget? child) {+ return IconButton(+ onPressed: () {+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();+ }+ },+ icon: const Icon(+ Icons.more_vert,+ color: Colors.white,),- ),- PopupMenuItem(- value: 1,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("弹幕切换")],+ );+ },+ menuChildren: [+ MenuItemButton(+ onPressed: () {+ widget.showDanmakuSwitch();+ },+ child: const Padding(+ padding: EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text("弹幕切换"),),),- PopupMenuItem(- value: 2,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("视频详情")],+ MenuItemButton(+ onPressed: () {+ showVideoInfo();+ },+ child: const Padding(+ padding: EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text("视频详情"),),),- PopupMenuItem(- value: 3,- child: Row(- mainAxisSize: MainAxisSize.min,- children: [Text("远程播放")],+ MenuItemButton(+ onPressed: () {+ bool needRestart = playerController.playing;+ playerController.pause();+ RemotePlay()+ .castVideo(context,+ videoPageController.currentPlugin.referer)+ .whenComplete(() {+ if (needRestart) {+ playerController.play();+ }+ });+ },+ child: const Padding(+ padding: EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text("远程播放"),),),- ];- },- onSelected: (value) {- if (value == 0) {- KazumiDialog.show(builder: (context) {- return DanmakuSettingsWindow(- danmakuController:- playerController.danmakuController);- });- }- if (value == 1) {- widget.showDanmakuSwitch();- }- if (value == 2) {- showVideoInfo();- }- if (value == 3) {- bool needRestart = playerController.playing;- playerController.pause();- RemotePlay()- .castVideo(context,- videoPageController.currentPlugin.referer)- .whenComplete(() {- if (needRestart) {- playerController.play();- }- });- }- },- )+ ]),],),),@@ -738,50 +653,13 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {visible: !playerController.lockPanel,child: SlideTransition(position: bottomOffsetAnimation,- child: Row(+ child: Column(children: [- IconButton(- color: Colors.white,- icon: Icon(playerController.playing- ? Icons.pause- : Icons.play_arrow),- onPressed: () {- playerController.playOrPause();- },- ),- // 更换选集- (videoPageController.isFullscreen ||- Utils.isTablet() ||- Utils.isDesktop())- ? IconButton(- color: Colors.white,- icon: const Icon(Icons.skip_next),- onPressed: () {- if (videoPageController.loading) {- return;- }- if (videoPageController.currentEpisode ==- videoPageController- .roadList[videoPageController.currentRoad]- .data- .length) {- KazumiDialog.showToast(- message: '已经是最新一集',- );- return;- }- KazumiDialog.showToast(- message:- '正在加载${videoPageController.roadList[videoPageController.currentRoad].identifier[videoPageController.currentEpisode]}');- widget.changeEpisode(- videoPageController.currentEpisode + 1,- currentRoad: videoPageController.currentRoad);- },- )- : Container(),- forwardIcon(),- Expanded(+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 10),child: ProgressBar(+ thumbRadius: 8,+ thumbGlowRadius: 18,timeLabelLocation: TimeLabelLocation.none,progress: playerController.currentPosition,buffered: playerController.buffer,@@ -800,72 +678,276 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {},),),- ((Utils.isCompact()) && !videoPageController.isFullscreen)- ? Container()- : Container(- padding: const EdgeInsets.only(left: 10.0),- child: Text(- "${Utils.durationToString(playerController.currentPosition)} / ${Utils.durationToString(playerController.duration)}",- style: TextStyle(- color: Colors.white,- fontSize: !Utils.isCompact() ? 16.0 : 12.0,- ),- ),- ),- // 弹幕相关- (playerController.danmakuOn)- ? IconButton(+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 10),+ child: Row(+ children: [+ IconButton(color: Colors.white,- icon: const Icon(Icons.notes),+ icon: Icon(playerController.playing+ ? Icons.pause_rounded+ : Icons.play_arrow_rounded),onPressed: () {- if (playerController.danDanmakus.isEmpty) {- KazumiDialog.showToast(- message: '当前剧集不支持弹幕发送的说',+ playerController.playOrPause();+ },+ ),+ // 更换选集+ (videoPageController.isFullscreen ||+ Utils.isTablet() ||+ Utils.isDesktop())+ ? IconButton(+ color: Colors.white,+ icon: const Icon(Icons.skip_next_rounded),+ onPressed: () {+ if (videoPageController.loading) {+ return;+ }+ if (videoPageController.currentEpisode ==+ videoPageController+ .roadList[+ videoPageController.currentRoad]+ .data+ .length) {+ KazumiDialog.showToast(+ message: '已经是最新一集',+ );+ return;+ }+ KazumiDialog.showToast(+ message:+ '正在加载${videoPageController.roadList[videoPageController.currentRoad].identifier[videoPageController.currentEpisode]}');+ widget.changeEpisode(+ videoPageController.currentEpisode + 1,+ currentRoad:+ videoPageController.currentRoad);+ },+ )+ : Container(),+ ((Utils.isCompact()) &&+ !videoPageController.isFullscreen)+ ? Container()+ : Container(+ padding: const EdgeInsets.only(left: 10.0),+ child: Text(+ "${Utils.durationToString(playerController.currentPosition)} / ${Utils.durationToString(playerController.duration)}",+ style: TextStyle(+ color: Colors.white,+ fontSize:+ !Utils.isCompact() ? 16.0 : 12.0,+ fontFeatures: const [+ FontFeature.tabularFigures(),+ ],+ ),+ ),+ ),+ Expanded(+ child: LayoutBuilder(+ builder: (context, constraints) {+ bool isSpaceEnough = constraints.maxWidth > 600;+ return Center(+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ IconButton(+ color: Colors.white,+ icon: Icon(playerController.danmakuOn+ ? Icons.subtitles_rounded+ : Icons.subtitles_off_rounded),+ onPressed: () {+ _handleDanmaku();+ setState(() {});+ },+ tooltip: playerController.danmakuOn+ ? '关闭弹幕(d)'+ : '打开弹幕(d)',+ ),+ IconButton(+ tooltip: '弹幕设置',+ onPressed: () {+ widget.keyboardFocus.requestFocus();+ KazumiDialog.show(builder: (context) {+ return DanmakuSettingsWindow(+ danmakuController:+ playerController+ .danmakuController);+ });+ },+ color: Colors.white,+ icon: const Icon(Icons.tune_rounded),+ ),+ if (isSpaceEnough) danmakuTextField(),+ ],+ ),);- return;- }- showShootDanmakuSheet();+ },+ ),+ ),+ // 超分辨率+ MenuAnchor(+ builder: (BuildContext context,+ MenuController controller, Widget? child) {+ return TextButton(+ onPressed: () {+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();+ }+ },+ child: const Text(+ '超分辨率',+ style: TextStyle(color: Colors.white),+ ),+ );},- )- : Container(),- IconButton(- color: Colors.white,- icon: Icon(playerController.danmakuOn- ? Icons.subtitles- : Icons.subtitles_off),- onPressed: () {- _handleDanmaku();- },- ),- (!videoPageController.isFullscreen &&- !Utils.isTablet() &&- !Utils.isDesktop())- ? Container()- : IconButton(- color: Colors.white,- icon: Icon(videoPageController.showTabBody- ? Icons.menu_open- : Icons.menu_open_outlined),- onPressed: () {- videoPageController.showTabBody =- !videoPageController.showTabBody;- widget.openMenu();+ menuChildren: List<MenuItemButton>.generate(+ 3,+ (int index) => MenuItemButton(+ onPressed: () =>+ playerController.setShader(index + 1),+ child: Padding(+ padding:+ const EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text(+ index + 1 == 1+ ? 'OFF'+ : index + 1 == 2+ ? 'Efficiency'+ : 'Quality',+ style: TextStyle(+ color: playerController+ .superResolutionType ==+ index + 1+ ? Theme.of(context)+ .colorScheme+ .primary+ : Colors.white,+ ),+ ),+ ),+ ),+ ),+ ),+ // 倍速播放+ MenuAnchor(+ builder: (BuildContext context,+ MenuController controller, Widget? child) {+ return TextButton(+ onPressed: () {+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();+ }+ },+ child: Text(+ playerController.playerSpeed == 1.0+ ? '倍速'+ : '${playerController.playerSpeed}x',+ style: const TextStyle(color: Colors.white),+ ),+ );},+ menuChildren: [+ for (final double i+ in defaultPlaySpeedList) ...<MenuItemButton>[+ MenuItemButton(+ onPressed: () async {+ await widget.setPlaybackSpeed(i);+ },+ child: Padding(+ padding: const EdgeInsets.fromLTRB(+ 0, 10, 10, 10),+ child: Text(+ '${i}x',+ style: TextStyle(+ color:+ i == playerController.playerSpeed+ ? Theme.of(context)+ .colorScheme+ .primary+ : Colors.white),+ ),+ ),+ ),+ ],+ ],),- (Utils.isTablet() &&- videoPageController.isFullscreen &&- MediaQuery.of(context).size.height <- MediaQuery.of(context).size.width)- ? Container()- : IconButton(- color: Colors.white,- icon: Icon(videoPageController.isFullscreen- ? Icons.fullscreen_exit- : Icons.fullscreen),- onPressed: () {- widget.handleFullscreen();+ MenuAnchor(+ builder: (BuildContext context,+ MenuController controller, Widget? child) {+ return IconButton(+ onPressed: () {+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();+ }+ },+ icon: const Icon(+ Icons.aspect_ratio_rounded,+ color: Colors.white,+ ),+ tooltip: '视频比例',+ );},+ menuChildren: List<MenuItemButton>.generate(+ 3,+ (int index) => MenuItemButton(+ onPressed: () => playerController+ .aspectRatioType = index + 1,+ child: Padding(+ padding:+ const EdgeInsets.fromLTRB(0, 10, 10, 10),+ child: Text(+ index + 1 == 1+ ? 'AUTO'+ : index + 1 == 2+ ? 'COVER'+ : 'FILL',+ style: TextStyle(+ color: index + 1 ==+ playerController.aspectRatioType+ ? Theme.of(context)+ .colorScheme+ .primary+ : Colors.white),+ ),+ ),+ ),+ ),),+ (!videoPageController.isFullscreen &&+ !Utils.isTablet() &&+ !Utils.isDesktop())+ ? Container()+ : IconButton(+ color: Colors.white,+ icon: const Icon(Icons.menu_open_rounded),+ onPressed: () {+ videoPageController.showTabBody =+ !videoPageController.showTabBody;+ widget.openMenu();+ },+ ),+ (Utils.isTablet() &&+ videoPageController.isFullscreen &&+ MediaQuery.of(context).size.height <+ MediaQuery.of(context).size.width)+ ? Container()+ : IconButton(+ color: Colors.white,+ icon: Icon(videoPageController.isFullscreen+ ? Icons.fullscreen_exit_rounded+ : Icons.fullscreen_rounded),+ onPressed: () {+ widget.handleFullscreen();+ },+ ),+ ],+ ),+ ),+ const SizedBox(height: 6),],),),