基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。
refactor: reduce mobx rebuild scope for downloads and player
Predidite82ca2ed9d75
diff --git a/lib/pages/download/download_controller.dart b/lib/pages/download/download_controller.dartindex bc253452..35fe034a 100644--- a/lib/pages/download/download_controller.dart+++ b/lib/pages/download/download_controller.dart@@ -27,18 +27,20 @@ abstract class _DownloadController with Store {@observableObservableList<DownloadRecord> records = ObservableList<DownloadRecord>();+ final ObservableList<String> recordKeys = ObservableList<String>();+ final ObservableMap<String, DownloadRecord> recordByKey =+ ObservableMap<String, DownloadRecord>();final List<_ResolveRequest> _resolveQueue = [];bool _isResolving = false;bool _isBackgroundServiceInitialized = false;Future<void> init() async {- final temp = _repository.getAllRecords();- records.clear();- records.addAll(temp);+ _replaceRecords(_repository.getAllRecords());// Reset any incomplete states to 'paused' on startup// This includes 'pending' because the in-memory queue is lost on restart+ var resetIncompleteRecords = false;for (final record in records) {bool changed = false;for (final entry in record.episodes.entries) {@@ -50,9 +52,13 @@ abstract class _DownloadController with Store {}}if (changed) {- _repository.putRecord(record);+ resetIncompleteRecords = true;+ await _repository.putRecord(record);}}+ if (resetIncompleteRecords) {+ _replaceRecords(_repository.getAllRecords());+ }// 将旧 Hive danmakuData 迁移到独立文件,防止 Hive compact 时 OOMawait _migrateDanmakuDataToFiles();@@ -140,7 +146,7 @@ abstract class _DownloadController with Store {if (isFinalState ||now.difference(_lastUiUpdateTime) >= _uiUpdateInterval) {_lastUiUpdateTime = now;- refreshRecords();+ _refreshRecord(recordKey);_updateBackgroundNotification();}}@@ -183,7 +189,7 @@ abstract class _DownloadController with Store {int totalCount = 0;double totalProgress = 0;- for (final record in records) {+ for (final record in recordByKey.values) {for (final episode in record.episodes.values) {if (episode.status == DownloadStatus.downloading) {activeCount++;@@ -213,9 +219,90 @@ abstract class _DownloadController with Store {@actionvoid refreshRecords() {- final temp = _repository.getAllRecords();- records.clear();- records.addAll(temp);+ _replaceRecords(_repository.getAllRecords());+ }++ void _replaceRecords(List<DownloadRecord> nextRecords) {+ runInAction(() {+ records+ ..clear()+ ..addAll(nextRecords.map(_cloneRecord));++ recordKeys+ ..clear()+ ..addAll(nextRecords.map((record) => record.key));++ recordByKey+ ..clear()+ ..addEntries(nextRecords.map(+ (record) => MapEntry(record.key, _cloneRecord(record)),+ ));+ });+ }++ void _refreshRecord(String recordKey) {+ final record = _repository.getRecord(recordKey);+ runInAction(() {+ if (record == null || record.episodes.isEmpty) {+ recordByKey.remove(recordKey);+ recordKeys.remove(recordKey);+ records.removeWhere((item) => item.key == recordKey);+ return;+ }++ final snapshot = _cloneRecord(record);+ recordByKey[recordKey] = snapshot;+ final keyIndex = recordKeys.indexOf(recordKey);+ if (keyIndex == -1) {+ recordKeys.add(recordKey);+ }++ final recordIndex = records.indexWhere((item) => item.key == recordKey);+ if (recordIndex == -1) {+ records.add(_cloneRecord(record));+ } else {+ records[recordIndex] = _cloneRecord(record);+ }+ });+ }++ DownloadRecord? getRecordSnapshot(String recordKey) => recordByKey[recordKey];++ DownloadRecord _cloneRecord(DownloadRecord record) {+ return DownloadRecord(+ record.bangumiId,+ record.bangumiName,+ record.bangumiCover,+ record.pluginName,+ record.episodes.map(+ (episodeNumber, episode) => MapEntry(+ episodeNumber,+ _cloneEpisode(episode),+ ),+ ),+ record.createdAt,+ );+ }++ DownloadEpisode _cloneEpisode(DownloadEpisode episode) {+ return DownloadEpisode(+ episode.episodeNumber,+ episode.episodeName,+ episode.road,+ episode.status,+ episode.progressPercent,+ episode.totalSegments,+ episode.downloadedSegments,+ episode.localM3u8Path,+ episode.downloadDirectory,+ episode.networkM3u8Url,+ episode.completedAt,+ episode.errorMessage,+ episode.totalBytes,+ episode.episodePageUrl,+ danmakuData: episode.danmakuData,+ danDanBangumiID: episode.danDanBangumiID,+ );}Plugin? _findPlugin(String pluginName) {@@ -478,7 +565,7 @@ abstract class _DownloadController with Store {freshEpisode.status = DownloadStatus.downloading;await _repository.updateEpisode(request.recordKey, request.episodeNumber, freshEpisode);- refreshRecords();+ _refreshRecord(request.recordKey);await _startBackgroundServiceIfNeeded();@@ -576,7 +663,7 @@ abstract class _DownloadController with Store {episode.status = DownloadStatus.failed;episode.errorMessage = message;_repository.updateEpisode(recordKey, episodeNumber, episode);- refreshRecords();+ _refreshRecord(recordKey);KazumiLogger().w('DownloadController: episode $episodeNumber failed: $message');}@@ -595,7 +682,7 @@ abstract class _DownloadController with Store {if (episode != null) {episode.status = DownloadStatus.paused;await _repository.updateEpisode(recordKey, episodeNumber, episode);- refreshRecords();+ _refreshRecord(recordKey);_updateBackgroundNotification();}}@@ -649,7 +736,7 @@ abstract class _DownloadController with Store {episode.progressPercent = 0.0;episode.downloadedSegments = 0;await _repository.updateEpisode(recordKey, episodeNumber, episode);- refreshRecords();+ _refreshRecord(recordKey);await _startBackgroundServiceIfNeeded();@@ -673,7 +760,7 @@ abstract class _DownloadController with Store {episode.progressPercent = 0.0;episode.downloadedSegments = 0;await _repository.updateEpisode(recordKey, episodeNumber, episode);- refreshRecords();+ _refreshRecord(recordKey);_resolveQueue.add(_ResolveRequest(recordKey: recordKey,@@ -695,7 +782,7 @@ abstract class _DownloadController with Store {await _downloadManager.deleteEpisodeFiles(bangumiId, pluginName, episodeNumber);await _repository.deleteEpisode(recordKey, episodeNumber);- refreshRecords();+ _refreshRecord(recordKey);_updateBackgroundNotification();}@@ -711,7 +798,7 @@ abstract class _DownloadController with Store {_resolveQueue.removeWhere((r) => r.recordKey == recordKey);await _downloadManager.deleteRecordFiles(bangumiId, pluginName);await _repository.deleteRecord(recordKey);- refreshRecords();+ _refreshRecord(recordKey);_updateBackgroundNotification();}@@ -725,7 +812,7 @@ abstract class _DownloadController with Store {await _downloadManager.deleteEpisodeFiles(bangumiId, pluginName, episodeNumber);await _repository.deleteEpisode(recordKey, episodeNumber);- refreshRecords();+ _refreshRecord(recordKey);_updateBackgroundNotification();}@@ -753,7 +840,7 @@ abstract class _DownloadController with Store {episode.status = DownloadStatus.downloading;episode.errorMessage = '';await _repository.updateEpisode(recordKey, episodeNumber, episode);- refreshRecords();+ _refreshRecord(recordKey);await _startBackgroundServiceIfNeeded();@@ -775,7 +862,7 @@ abstract class _DownloadController with Store {episode.status = DownloadStatus.resolving;episode.errorMessage = '';await _repository.updateEpisode(recordKey, episodeNumber, episode);- refreshRecords();+ _refreshRecord(recordKey);_resolveQueue.insert(0,diff --git a/lib/pages/download/download_page.dart b/lib/pages/download/download_page.dartindex 18906eed..16fd0607 100644--- a/lib/pages/download/download_page.dart+++ b/lib/pages/download/download_page.dart@@ -31,7 +31,8 @@ class _DownloadPageState extends State<DownloadPage> {return Scaffold(appBar: const SysAppBar(title: Text('下载管理')),body: Observer(builder: (context) {- if (downloadController.records.isEmpty) {+ final recordKeys = downloadController.recordKeys.toList();+ if (recordKeys.isEmpty) {return Center(child: Column(mainAxisSize: MainAxisSize.min,@@ -39,7 +40,10 @@ class _DownloadPageState extends State<DownloadPage> {Icon(Icons.download_rounded,size: 72,- color: Theme.of(context).colorScheme.outline.withValues(alpha: 0.5),+ color: Theme.of(context)+ .colorScheme+ .outline+ .withValues(alpha: 0.5),),const SizedBox(height: 16),Text(@@ -54,85 +58,90 @@ class _DownloadPageState extends State<DownloadPage> {}return ListView.builder(padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),- itemCount: downloadController.records.length,+ itemCount: recordKeys.length,itemBuilder: (context, index) {- final record = downloadController.records[index];- return _buildRecordCard(record);+ return _buildRecordCard(recordKeys[index]);},);}),);}- Widget _buildRecordCard(DownloadRecord record) {- final episodes = record.episodes.values.toList()- ..sort((a, b) => a.episodeNumber.compareTo(b.episodeNumber));- final completedCount = downloadController.completedCount(record);+ Widget _buildRecordCard(String recordKey) {+ return Observer(builder: (context) {+ final record = downloadController.getRecordSnapshot(recordKey);+ if (record == null) {+ return const SizedBox.shrink();+ }- return Card(- margin: const EdgeInsets.only(bottom: 12),- clipBehavior: Clip.antiAlias,- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- // Header- ListTile(- leading: ClipRRect(- borderRadius: BorderRadius.circular(4),- child: Image.network(- record.bangumiCover,- width: 48,- height: 64,- fit: BoxFit.cover,- errorBuilder: (_, __, ___) => Container(+ final episodes = record.episodes.values.toList()+ ..sort((a, b) => a.episodeNumber.compareTo(b.episodeNumber));+ final completedCount = downloadController.completedCount(record);++ return Card(+ margin: const EdgeInsets.only(bottom: 12),+ clipBehavior: Clip.antiAlias,+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ ListTile(+ leading: ClipRRect(+ borderRadius: BorderRadius.circular(4),+ child: Image.network(+ record.bangumiCover,width: 48,height: 64,- color: Theme.of(context).colorScheme.surfaceContainerHighest,- child: const Icon(Icons.movie_outlined),+ fit: BoxFit.cover,+ errorBuilder: (_, __, ___) => Container(+ width: 48,+ height: 64,+ color:+ Theme.of(context).colorScheme.surfaceContainerHighest,+ child: const Icon(Icons.movie_outlined),+ ),),),- ),- title: Text(- record.bangumiName,- maxLines: 1,- overflow: TextOverflow.ellipsis,- ),- subtitle: Text(- '来源: ${record.pluginName} · $completedCount/${episodes.length} 已完成',- style: TextStyle(- fontSize: 12,- color: Theme.of(context).colorScheme.outline,+ title: Text(+ record.bangumiName,+ maxLines: 1,+ overflow: TextOverflow.ellipsis,),- ),- trailing: PopupMenuButton<String>(- onSelected: (value) {- if (value == 'delete') {- _confirmDeleteRecord(record);- } else if (value == 'resume_all') {- downloadController.resumeAllDownloads(- record.bangumiId,- record.pluginName,- );- KazumiDialog.showToast(message: '已开始恢复下载');- }- },- itemBuilder: (context) => [- const PopupMenuItem(- value: 'resume_all',- child: Text('开始全部'),- ),- const PopupMenuItem(- value: 'delete',- child: Text('删除全部'),+ subtitle: Text(+ '来源: ${record.pluginName} · $completedCount/${episodes.length} 已完成',+ style: TextStyle(+ fontSize: 12,+ color: Theme.of(context).colorScheme.outline,),- ],+ ),+ trailing: PopupMenuButton<String>(+ onSelected: (value) {+ if (value == 'delete') {+ _confirmDeleteRecord(record);+ } else if (value == 'resume_all') {+ downloadController.resumeAllDownloads(+ record.bangumiId,+ record.pluginName,+ );+ KazumiDialog.showToast(message: '已开始恢复下载');+ }+ },+ itemBuilder: (context) => [+ const PopupMenuItem(+ value: 'resume_all',+ child: Text('开始全部'),+ ),+ const PopupMenuItem(+ value: 'delete',+ child: Text('删除全部'),+ ),+ ],+ ),),- ),- // Episode list- ...episodes.map((ep) => _buildEpisodeTile(record, ep)),- ],- ),- );+ ...episodes.map((ep) => _buildEpisodeTile(record, ep)),+ ],+ ),+ );+ });}Widget _buildEpisodeTile(DownloadRecord record, DownloadEpisode episode) {@@ -337,7 +346,6 @@ class _DownloadPageState extends State<DownloadPage> {return;}- // 构建 BangumiItemfinal bangumiItem = BangumiItem(id: record.bangumiId,type: 2,@@ -356,13 +364,11 @@ class _DownloadPageState extends State<DownloadPage> {info: '',);- // 获取所有已下载集数(通过 Controller 委托给 Repository 层)final downloadedEpisodes = downloadController.getCompletedEpisodes(record.bangumiId,record.pluginName,);- // 初始化离线模式final videoPageController = Modular.get<VideoPageController>();videoPageController.initForOfflinePlayback(bangumiItem: bangumiItem,@@ -374,7 +380,6 @@ class _DownloadPageState extends State<DownloadPage> {downloadedEpisodes: downloadedEpisodes,);- // 导航到 VideoPageModular.to.pushNamed('/video/');}@@ -382,7 +387,8 @@ class _DownloadPageState extends State<DownloadPage> {KazumiDialog.show(builder: (context) => AlertDialog(title: const Text('删除下载'),- content: Text('确定要删除「${episode.episodeName.isNotEmpty ? episode.episodeName : '第${episode.episodeNumber}集'}」的下载文件吗?'),+ content: Text(+ '确定要删除「${episode.episodeName.isNotEmpty ? episode.episodeName : '第${episode.episodeNumber}集'}」的下载文件吗?'),actions: [TextButton(onPressed: () => KazumiDialog.dismiss(),diff --git a/lib/pages/player/player_controller.dart b/lib/pages/player/player_controller.dartindex b4df298f..c839d66e 100644--- a/lib/pages/player/player_controller.dart+++ b/lib/pages/player/player_controller.dart@@ -552,6 +552,32 @@ abstract class _PlayerController with Store {} catch (_) {}}+ @action+ void syncPlaybackState() {+ final player = mediaPlayer;+ if (player == null) return;++ final state = player.state;+ if (playing != state.playing) {+ playing = state.playing;+ }+ if (isBuffering != state.buffering) {+ isBuffering = state.buffering;+ }+ if (currentPosition != state.position) {+ currentPosition = state.position;+ }+ if (buffer != state.buffer) {+ buffer = state.buffer;+ }+ if (duration != state.duration) {+ duration = state.duration;+ }+ if (completed != state.completed) {+ completed = state.completed;+ }+ }+Future<void> playOrPause() async {if (mediaPlayer!.state.playing) {await pause();diff --git a/lib/pages/player/player_controller.g.dart b/lib/pages/player/player_controller.g.dartindex 7cf9ae2e..4f835505 100644--- a/lib/pages/player/player_controller.g.dart+++ b/lib/pages/player/player_controller.g.dart@@ -569,6 +569,20 @@ mixin _$PlayerController on _PlayerController, Store {});}+ late final _$_PlayerControllerActionController =+ ActionController(name: '_PlayerController', context: context);++ @override+ void syncPlaybackState() {+ final _$actionInfo = _$_PlayerControllerActionController.startAction(+ name: '_PlayerController.syncPlaybackState');+ try {+ return super.syncPlaybackState();+ } finally {+ _$_PlayerControllerActionController.endAction(_$actionInfo);+ }+ }+@overrideString toString() {return '''diff --git a/lib/pages/player/player_item.dart b/lib/pages/player/player_item.dartindex a971cabc..4589d2a3 100644--- a/lib/pages/player/player_item.dart+++ b/lib/pages/player/player_item.dart@@ -818,12 +818,7 @@ class _PlayerItemState extends State<PlayerItem>Timer getPlayerTimer() {return Timer.periodic(const Duration(seconds: 1), (timer) {- playerController.playing = playerController.playerPlaying;- playerController.isBuffering = playerController.playerBuffering;- playerController.currentPosition = playerController.playerPosition;- playerController.buffer = playerController.playerBuffer;- playerController.duration = playerController.playerDuration;- playerController.completed = playerController.playerCompleted;+ playerController.syncPlaybackState();unawaited(_updateAndroidPIPActions());_syncAudioServiceState();// 弹幕相关diff --git a/lib/pages/player/player_item_panel.dart b/lib/pages/player/player_item_panel.dartindex 5035f4e6..868a6296 100644--- a/lib/pages/player/player_item_panel.dart+++ b/lib/pages/player/player_item_panel.dart@@ -88,9 +88,10 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {final VideoPageController videoPageController =Modular.get<VideoPageController>();final PlayerController playerController = Modular.get<PlayerController>();- final DownloadController downloadController = Modular.get<DownloadController>();+ final DownloadController downloadController =+ Modular.get<DownloadController>();final TextEditingController textController = TextEditingController();- final FocusNode textFieldFocus = FocusNode();+ final FocusNode textFieldFocus = FocusNode();// SVG CachesString? cachedSvgString;Widget? cachedDanmakuOnIcon;@@ -135,7 +136,8 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {TextButton(onPressed: () {textFieldFocus.unfocus();- widget.showDanmakuDestinationPickerAndSend(textController.text);+ widget+ .showDanmakuDestinationPickerAndSend(textController.text);textController.clear();},style: TextButton.styleFrom(@@ -146,7 +148,8 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {? Theme.of(context).colorScheme.primaryContainer: Theme.of(context).disabledColor,shape: RoundedRectangleBorder(- borderRadius: BorderRadius.circular(Utils.isDesktop() ? 8 : 20),+ borderRadius:+ BorderRadius.circular(Utils.isDesktop() ? 8 : 20),),),child: const Text('发送'),@@ -276,8 +279,6 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {});}--@overridevoid initState() {super.initState();@@ -305,7 +306,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);cacheSvgIcons();}-+void cacheSvgIcons() {cachedDanmakuOffIcon = RepaintBoundary(child: SvgPicture.asset(@@ -321,7 +322,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),);}-+Widget danmakuOnIcon(BuildContext context) {final colorHex = Theme.of(context).colorScheme@@ -365,9 +366,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {},tooltip: playerController.danmakuLoading? '弹幕加载中...'- : (playerController.danmakuOn- ? '关闭弹幕'- : '打开弹幕'),+ : (playerController.danmakuOn ? '关闭弹幕' : '打开弹幕'),);}@@ -392,17 +391,16 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {@overrideWidget build(BuildContext context) {- return Observer(builder: (context) {- return Stack(- alignment: Alignment.center,- children: [- //顶部渐变区域- AnimatedPositioned(- duration: const Duration(seconds: 1),- top: 0,- left: 0,- right: 0,- child: Visibility(+ return Stack(+ alignment: Alignment.center,+ children: [+ AnimatedPositioned(+ duration: const Duration(seconds: 1),+ top: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -437,16 +435,16 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),),),- ),- ),-- //底部渐变区域- AnimatedPositioned(- duration: const Duration(seconds: 1),- bottom: 0,- left: 0,- right: 0,- child: Visibility(+ );+ }),+ ),+ AnimatedPositioned(+ duration: const Duration(seconds: 1),+ bottom: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -481,12 +479,13 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),),),- ),- ),- // 顶部进度条- Positioned(- top: 25,- child: playerController.showSeekTime+ );+ }),+ ),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showSeekTime? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -494,7 +493,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: Text(playerController.currentPosition.compareTo(@@ -509,11 +508,12 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),],)- : Container()),- // 顶部播放速度条- Positioned(- top: 25,- child: playerController.showPlaySpeed+ : Container();+ })),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showPlaySpeed? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -521,7 +521,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: const Row(children: <Widget>[@@ -537,11 +537,12 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),],)- : Container()),- // 亮度条- Positioned(- top: 25,- child: playerController.showBrightness+ : Container();+ })),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showBrightness? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -549,7 +550,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: Row(children: <Widget>[@@ -565,11 +566,12 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {)),],)- : Container()),- // 音量条- Positioned(- top: 25,- child: playerController.showVolume+ : Container();+ })),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showVolume? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -577,7 +579,7 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: Row(children: <Widget>[@@ -593,15 +595,16 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {)),],)- : Container()),- // 右侧锁定按钮- (Utils.isDesktop() || !videoPageController.isFullscreen)- ? Container()- : Positioned(- right: 0,- top: 0,- bottom: 0,- child: Visibility(+ : Container();+ })),+ (Utils.isDesktop() || !videoPageController.isFullscreen)+ ? Container()+ : Positioned(+ right: 0,+ top: 0,+ bottom: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: widget.disableAnimations? playerController.showVideoController: true,@@ -610,14 +613,15 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {: SlideTransition(position: leftOffsetAnimation,child: leftControlWidget),- ),- ),- // 自定义顶部组件- Positioned(- top: 0,- left: 0,- right: 0,- child: Visibility(+ );+ }),+ ),+ Positioned(+ top: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -626,14 +630,15 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {? topControlWidget: SlideTransition(position: topOffsetAnimation, child: topControlWidget),- ),- ),- // 自定义播放器底部组件- Positioned(- bottom: 0,- left: 0,- right: 0,- child: Visibility(+ );+ }),+ ),+ Positioned(+ bottom: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -643,267 +648,374 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {: SlideTransition(position: bottomOffsetAnimation,child: bottomControlWidget),- ),- ),- ],- );- });+ );+ }),+ ),+ ],+ );}Widget get bottomControlWidget {- return Observer(- builder: (context) {- return SafeArea(- top: false,- bottom: videoPageController.isFullscreen,- left: videoPageController.isFullscreen,- right: videoPageController.isFullscreen,- child: MouseRegion(- cursor: (videoPageController.isFullscreen &&- !playerController.showVideoController)- ? SystemMouseCursors.none- : SystemMouseCursors.basic,- onEnter: (_) {- widget.cancelHideTimer();- },- onExit: (_) {- widget.cancelHideTimer();- widget.startHideTimer();- },- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- if (!Utils.isDesktop() && !Utils.isTablet())- Container(- padding: const EdgeInsets.only(left: 10.0, bottom: 10),- child: Text(- "${Utils.durationToString(playerController.currentPosition)} / ${Utils.durationToString(playerController.duration)}",- style: const TextStyle(- color: Colors.white,- fontSize: 12.0,- fontFeatures: [- FontFeature.tabularFigures(),- ],- ),- ),- ),- Padding(- padding: const EdgeInsets.symmetric(horizontal: 10),- child: ProgressBar(- thumbRadius: 8,- thumbGlowRadius: 18,- timeLabelLocation: Utils.isTablet()- ? TimeLabelLocation.sides- : TimeLabelLocation.none,- timeLabelTextStyle: const TextStyle(+ return Observer(builder: (context) {+ return SafeArea(+ top: false,+ bottom: videoPageController.isFullscreen,+ left: videoPageController.isFullscreen,+ right: videoPageController.isFullscreen,+ child: MouseRegion(+ cursor: (videoPageController.isFullscreen &&+ !playerController.showVideoController)+ ? SystemMouseCursors.none+ : SystemMouseCursors.basic,+ onEnter: (_) {+ widget.cancelHideTimer();+ },+ onExit: (_) {+ widget.cancelHideTimer();+ widget.startHideTimer();+ },+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ if (!Utils.isDesktop() && !Utils.isTablet())+ Container(+ padding: const EdgeInsets.only(left: 10.0, bottom: 10),+ child: Text(+ "${Utils.durationToString(playerController.currentPosition)} / ${Utils.durationToString(playerController.duration)}",+ style: const TextStyle(color: Colors.white,fontSize: 12.0,fontFeatures: [FontFeature.tabularFigures(),],),- progress: playerController.currentPosition,- buffered: playerController.buffer,- total: playerController.duration,- onSeek: (duration) {- playerController.seek(duration);- },- onDragStart: (details) {- widget.handleProgressBarDragStart(details);- },- onDragUpdate: (details) =>- {playerController.currentPosition = details.timeStamp},- onDragEnd: () {- widget.handleProgressBarDragEnd();- },),),- Padding(- padding: const EdgeInsets.symmetric(horizontal: 10),- child: Row(- children: [+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 10),+ child: ProgressBar(+ thumbRadius: 8,+ thumbGlowRadius: 18,+ timeLabelLocation: Utils.isTablet()+ ? TimeLabelLocation.sides+ : TimeLabelLocation.none,+ timeLabelTextStyle: const TextStyle(+ color: Colors.white,+ fontSize: 12.0,+ fontFeatures: [+ FontFeature.tabularFigures(),+ ],+ ),+ progress: playerController.currentPosition,+ buffered: playerController.buffer,+ total: playerController.duration,+ onSeek: (duration) {+ playerController.seek(duration);+ },+ onDragStart: (details) {+ widget.handleProgressBarDragStart(details);+ },+ onDragUpdate: (details) =>+ {playerController.currentPosition = details.timeStamp},+ onDragEnd: () {+ widget.handleProgressBarDragEnd();+ },+ ),+ ),+ Padding(+ padding: const EdgeInsets.symmetric(horizontal: 10),+ child: Row(+ children: [+ IconButton(+ color: Colors.white,+ icon: Icon(playerController.playing+ ? Icons.pause_rounded+ : Icons.play_arrow_rounded),+ tooltip: playerController.playing ? '暂停' : '播放',+ onPressed: () {+ playerController.playOrPause();+ },+ ),+ // 更换选集+ if (videoPageController.isFullscreen ||+ Utils.isTablet() ||+ Utils.isDesktop())+ IconButton(+ color: Colors.white,+ icon: const Icon(Icons.skip_next_rounded),+ tooltip: '下一集',+ onPressed: () => widget.handlePreNextEpisode('next'),+ ),+ if (Utils.isDesktop())+ Container(+ padding: const EdgeInsets.only(left: 10.0),+ child: Text(+ "${Utils.durationToString(playerController.currentPosition)} / ${Utils.durationToString(playerController.duration)}",+ style: const TextStyle(+ color: Colors.white,+ fontSize: 16.0,+ fontFeatures: [+ FontFeature.tabularFigures(),+ ],+ ),+ ),+ ),+ if (Utils.isDesktop())+ Expanded(+ child: LayoutBuilder(+ builder: (context, constraints) {+ bool isSpaceEnough = constraints.maxWidth > 600;+ return Center(+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ _buildDanmakuToggleButton(context),+ IconButton(+ onPressed: () {+ widget.keyboardFocus.requestFocus();+ showModalBottomSheet(+ isScrollControlled: true,+ constraints: BoxConstraints(+ maxHeight: MediaQuery.of(context)+ .size+ .height *+ 3 /+ 4,+ maxWidth: (Utils.isDesktop() ||+ Utils.isTablet())+ ? MediaQuery.of(context)+ .size+ .width *+ 9 /+ 16+ : MediaQuery.of(context)+ .size+ .width),+ clipBehavior: Clip.antiAlias,+ context: context,+ builder: (context) {+ return DanmakuSettingsSheet(+ danmakuController:+ playerController+ .danmakuController,+ onUpdateDanmakuSpeed:+ playerController+ .updateDanmakuSpeed,+ );+ });+ },+ color: Colors.white,+ icon: cachedDanmakuSettingIcon!,+ tooltip: '弹幕设置',+ ),+ if (isSpaceEnough) danmakuTextField,+ ],+ ),+ );+ },+ ),+ ),+ if (!Utils.isDesktop()) ...[IconButton(color: Colors.white,- icon: Icon(playerController.playing- ? Icons.pause_rounded- : Icons.play_arrow_rounded),- tooltip: playerController.playing ? '暂停' : '播放',+ icon: playerController.danmakuOn+ ? danmakuOnIcon(context)+ : cachedDanmakuOffIcon!,onPressed: () {- playerController.playOrPause();+ widget.handleDanmaku();},+ tooltip: playerController.danmakuOn ? '关闭弹幕' : '打开弹幕',),- // 更换选集- if (videoPageController.isFullscreen ||- Utils.isTablet() ||- Utils.isDesktop())+ if (playerController.danmakuOn) ...[IconButton(+ onPressed: () {+ showModalBottomSheet(+ isScrollControlled: true,+ constraints: BoxConstraints(+ maxHeight:+ MediaQuery.of(context).size.height *+ 3 /+ 4,+ maxWidth: (Utils.isDesktop() ||+ Utils.isTablet())+ ? MediaQuery.of(context).size.width *+ 9 /+ 16+ : MediaQuery.of(context).size.width),+ clipBehavior: Clip.antiAlias,+ context: context,+ builder: (context) {+ return DanmakuSettingsSheet(+ danmakuController:+ playerController.danmakuController,+ onUpdateDanmakuSpeed:+ playerController.updateDanmakuSpeed,+ );+ });+ },color: Colors.white,- icon: const Icon(Icons.skip_next_rounded),- tooltip: '下一集',- onPressed: () => widget.handlePreNextEpisode('next'),+ icon: cachedDanmakuSettingIcon!,+ tooltip: '弹幕设置',),- if (Utils.isDesktop())- Container(- padding: const EdgeInsets.only(left: 10.0),- child: Text(- "${Utils.durationToString(playerController.currentPosition)} / ${Utils.durationToString(playerController.duration)}",- style: const TextStyle(- color: Colors.white,- fontSize: 16.0,- fontFeatures: [- FontFeature.tabularFigures(),- ],- ),+ Expanded(child: danmakuTextField),+ ],+ if (!playerController.danmakuOn) const Spacer(),+ ],+ // 超分辨率+ MenuAnchor(+ consumeOutsideTap: true,+ onOpen: () {+ widget.cancelHideTimer();+ playerController.canHidePlayerPanel = false;+ },+ onClose: () {+ widget.cancelHideTimer();+ widget.startHideTimer();+ playerController.canHidePlayerPanel = true;+ },+ 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),),- ),- if (Utils.isDesktop())- Expanded(- child: LayoutBuilder(- builder: (context, constraints) {- bool isSpaceEnough = constraints.maxWidth > 600;- return Center(- child: Row(- mainAxisAlignment: MainAxisAlignment.center,- children: [- _buildDanmakuToggleButton(context),- IconButton(- onPressed: () {- widget.keyboardFocus.requestFocus();- showModalBottomSheet(- isScrollControlled: true,- constraints: BoxConstraints(- maxHeight: MediaQuery.of(context)- .size- .height *- 3 /- 4,- maxWidth: (Utils.isDesktop() ||- Utils.isTablet())- ? MediaQuery.of(context)- .size- .width *- 9 /- 16- : MediaQuery.of(context)- .size- .width),- clipBehavior: Clip.antiAlias,- context: context,- builder: (context) {- return DanmakuSettingsSheet(- danmakuController:- playerController- .danmakuController,- onUpdateDanmakuSpeed:- playerController.updateDanmakuSpeed,- );- });- },- color: Colors.white,- icon: cachedDanmakuSettingIcon!,- tooltip: '弹幕设置',- ),- if (isSpaceEnough) danmakuTextField,- ],+ );+ },+ menuChildren: List<MenuItemButton>.generate(+ 3,+ (int index) => MenuItemButton(+ onPressed: () =>+ widget.handleSuperResolutionChange(index + 1),+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text(+ index + 1 == 1+ ? '关闭'+ : index + 1 == 2+ ? '效率档'+ : '质量档',+ style: TextStyle(+ color: playerController.superResolutionType ==+ index + 1+ ? Theme.of(context).colorScheme.primary+ : null,),- );- },+ ),+ ),),),- if (!Utils.isDesktop()) ...[- IconButton(- color: Colors.white,- icon: playerController.danmakuOn- ? danmakuOnIcon(context)- : cachedDanmakuOffIcon!,+ ),+ ),+ // 倍速播放+ MenuAnchor(+ consumeOutsideTap: true,+ onOpen: () {+ widget.cancelHideTimer();+ playerController.canHidePlayerPanel = false;+ },+ onClose: () {+ widget.cancelHideTimer();+ widget.startHideTimer();+ playerController.canHidePlayerPanel = true;+ },+ builder: (BuildContext context, MenuController controller,+ Widget? child) {+ return TextButton(onPressed: () {- widget.handleDanmaku();+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();+ }},- tooltip:- playerController.danmakuOn ? '关闭弹幕' : '打开弹幕',- ),- if (playerController.danmakuOn) ...[- IconButton(- onPressed: () {- showModalBottomSheet(- isScrollControlled: true,- constraints: BoxConstraints(- maxHeight:- MediaQuery.of(context).size.height *- 3 /- 4,- maxWidth:- (Utils.isDesktop() || Utils.isTablet())- ? MediaQuery.of(context).size.width *- 9 /- 16- : MediaQuery.of(context).size.width),- clipBehavior: Clip.antiAlias,- context: context,- builder: (context) {- return DanmakuSettingsSheet(- danmakuController:- playerController.danmakuController,- onUpdateDanmakuSpeed:- playerController.updateDanmakuSpeed,- );- });+ 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);},- color: Colors.white,- icon: cachedDanmakuSettingIcon!,- tooltip: '弹幕设置',+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text(+ '${i}x',+ style: TextStyle(+ color: i == playerController.playerSpeed+ ? Theme.of(context).colorScheme.primary+ : null,+ ),+ ),+ ),+ ),),- Expanded(child: danmakuTextField),],- if (!playerController.danmakuOn) const Spacer(),],- // 超分辨率- MenuAnchor(- consumeOutsideTap: true,- onOpen: () {- widget.cancelHideTimer();- playerController.canHidePlayerPanel = false;- },- onClose: () {- widget.cancelHideTimer();- widget.startHideTimer();- playerController.canHidePlayerPanel = true;- },- 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),- ),- );- },- menuChildren: List<MenuItemButton>.generate(- 3,- (int index) => MenuItemButton(+ ),+ MenuAnchor(+ consumeOutsideTap: true,+ onOpen: () {+ widget.cancelHideTimer();+ playerController.canHidePlayerPanel = false;+ },+ onClose: () {+ widget.cancelHideTimer();+ widget.startHideTimer();+ playerController.canHidePlayerPanel = true;+ },+ 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: [+ for (final entry in aspectRatioTypeMap.entries)+ MenuItemButton(onPressed: () =>- widget.handleSuperResolutionChange(index + 1),+ playerController.aspectRatioType = entry.key,child: Container(height: 48,constraints: BoxConstraints(minWidth: 112),child: Align(alignment: Alignment.centerLeft,child: Text(- index + 1 == 1- ? '关闭'- : index + 1 == 2- ? '效率档'- : '质量档',+ entry.value,style: TextStyle(- color: playerController.superResolutionType ==- index + 1+ color: entry.key ==+ playerController.aspectRatioType? Theme.of(context).colorScheme.primary: null,),@@ -911,358 +1023,274 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),),),- ),- ),- // 倍速播放- MenuAnchor(- consumeOutsideTap: true,- onOpen: () {- widget.cancelHideTimer();- playerController.canHidePlayerPanel = false;- },- onClose: () {- widget.cancelHideTimer();- widget.startHideTimer();- playerController.canHidePlayerPanel = true;- },- builder: (BuildContext context, MenuController controller,- Widget? child) {- return TextButton(+ ],+ ),+ (!videoPageController.isFullscreen &&+ !Utils.isTablet() &&+ !Utils.isDesktop())+ ? Container()+ : IconButton(+ color: Colors.white,+ icon: const Icon(Icons.menu_open_rounded),+ tooltip: '选集面板',onPressed: () {- if (controller.isOpen) {- controller.close();- } else {- controller.open();- }+ videoPageController.showTabBody =+ !videoPageController.showTabBody;+ widget.openMenu();},- 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: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- '${i}x',- style: TextStyle(- color: i == playerController.playerSpeed- ? Theme.of(context).colorScheme.primary- : null,- ),- ),- ),- ),- ),- ],- ],- ),- MenuAnchor(- consumeOutsideTap: true,- onOpen: () {- widget.cancelHideTimer();- playerController.canHidePlayerPanel = false;- },- onClose: () {- widget.cancelHideTimer();- widget.startHideTimer();- playerController.canHidePlayerPanel = true;- },- builder: (BuildContext context, MenuController controller,- Widget? child) {- return IconButton(+ ),+ (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),+ tooltip: videoPageController.isFullscreen+ ? '退出全屏'+ : '全屏',onPressed: () {- if (controller.isOpen) {- controller.close();- } else {- controller.open();- }+ widget.handleFullscreen();},- icon: const Icon(- Icons.aspect_ratio_rounded,- color: Colors.white,- ),- tooltip: '视频比例',- );- },- menuChildren: [- for (final entry in aspectRatioTypeMap.entries)- MenuItemButton(- onPressed: () =>- playerController.aspectRatioType = entry.key,- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- entry.value,- style: TextStyle(- color: entry.key ==- playerController.aspectRatioType- ? Theme.of(context).colorScheme.primary- : null,- ),- ),- ),- ),- ),- ],- ),- (!videoPageController.isFullscreen &&- !Utils.isTablet() &&- !Utils.isDesktop())- ? Container()- : IconButton(- color: Colors.white,- icon: const Icon(Icons.menu_open_rounded),- tooltip: '选集面板',- 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),- tooltip: videoPageController.isFullscreen- ? '退出全屏'- : '全屏',- onPressed: () {- widget.handleFullscreen();- },- ),- ],- ),+ ),+ ],),- if (Utils.isTablet() || Utils.isDesktop())- const SizedBox(height: 6),- ],- ),+ ),+ if (Utils.isTablet() || Utils.isDesktop())+ const SizedBox(height: 6),+ ],),- );- }- );+ ),+ );+ });}Widget get topControlWidget {- return Observer(- builder: (context) {- return EmbeddedNativeControlArea(- requireOffset: !videoPageController.isFullscreen,- child: SafeArea(- top: false,- bottom: false,- left: videoPageController.isFullscreen,- right: videoPageController.isFullscreen,- child: MouseRegion(- cursor: (videoPageController.isFullscreen &&- !playerController.showVideoController)- ? SystemMouseCursors.none- : SystemMouseCursors.basic,- onEnter: (_) {- widget.cancelHideTimer();- },- onExit: (_) {- widget.cancelHideTimer();- widget.startHideTimer();- },- child: Row(- children: [- IconButton(- color: Colors.white,- icon: const Icon(Icons.arrow_back_rounded),- tooltip: '返回',- onPressed: () {- widget.onBackPressed(context);- },- ),- // 拖动条- Expanded(- child: dtb.DragToMoveArea(- child: Text(- ' ${videoPageController.title} [${videoPageController.roadList[videoPageController.currentRoad].identifier[videoPageController.currentEpisode - 1]}]',- style: TextStyle(- color: Colors.white,- fontSize:- Theme.of(context).textTheme.titleMedium!.fontSize,- overflow: TextOverflow.ellipsis,- ),+ return Observer(builder: (context) {+ return EmbeddedNativeControlArea(+ requireOffset: !videoPageController.isFullscreen,+ child: SafeArea(+ top: false,+ bottom: false,+ left: videoPageController.isFullscreen,+ right: videoPageController.isFullscreen,+ child: MouseRegion(+ cursor: (videoPageController.isFullscreen &&+ !playerController.showVideoController)+ ? SystemMouseCursors.none+ : SystemMouseCursors.basic,+ onEnter: (_) {+ widget.cancelHideTimer();+ },+ onExit: (_) {+ widget.cancelHideTimer();+ widget.startHideTimer();+ },+ child: Row(+ children: [+ IconButton(+ color: Colors.white,+ icon: const Icon(Icons.arrow_back_rounded),+ tooltip: '返回',+ onPressed: () {+ widget.onBackPressed(context);+ },+ ),+ // 拖动条+ Expanded(+ child: dtb.DragToMoveArea(+ child: Text(+ ' ${videoPageController.title} [${videoPageController.roadList[videoPageController.currentRoad].identifier[videoPageController.currentEpisode - 1]}]',+ style: TextStyle(+ color: Colors.white,+ fontSize:+ Theme.of(context).textTheme.titleMedium!.fontSize,+ overflow: TextOverflow.ellipsis,),),),- // 跳过- forwardIcon(),- if ((Utils.isDesktop() && !videoPageController.isFullscreen) || Platform.isAndroid)- IconButton(- onPressed: () async {- if (Utils.isDesktop()) {- if (videoPageController.isPip) {- await PipUtils.exitDesktopPIPWindow();- } else {- await PipUtils.enterDesktopPIPWindow(- width: playerController.playerWidth,- height: playerController.playerHeight,- );- }- videoPageController.isPip = !videoPageController.isPip;- return;- }- final bool supported =- await PipUtils.isAndroidPIPSupported();- if (!supported) {- KazumiDialog.showToast(message: '当前设备不支持画中画');- return;+ ),+ // 跳过+ forwardIcon(),+ if ((Utils.isDesktop() && !videoPageController.isFullscreen) ||+ Platform.isAndroid)+ IconButton(+ onPressed: () async {+ if (Utils.isDesktop()) {+ if (videoPageController.isPip) {+ await PipUtils.exitDesktopPIPWindow();+ } else {+ await PipUtils.enterDesktopPIPWindow(+ width: playerController.playerWidth,+ height: playerController.playerHeight,+ );}- await PipUtils.updateAndroidPIPActions(- playing: playerController.playing,- danmakuEnabled: playerController.danmakuOn,- width: playerController.playerWidth,- height: playerController.playerHeight,- );- final bool entered = await PipUtils.enterAndroidPIPWindow(- width: playerController.playerWidth,- height: playerController.playerHeight,- );- if (!entered) {- KazumiDialog.showToast(message: '进入画中画失败');+ videoPageController.isPip = !videoPageController.isPip;+ return;+ }+ final bool supported =+ await PipUtils.isAndroidPIPSupported();+ if (!supported) {+ KazumiDialog.showToast(message: '当前设备不支持画中画');+ return;+ }+ await PipUtils.updateAndroidPIPActions(+ playing: playerController.playing,+ danmakuEnabled: playerController.danmakuOn,+ width: playerController.playerWidth,+ height: playerController.playerHeight,+ );+ final bool entered = await PipUtils.enterAndroidPIPWindow(+ width: playerController.playerWidth,+ height: playerController.playerHeight,+ );+ if (!entered) {+ KazumiDialog.showToast(message: '进入画中画失败');+ }+ },+ tooltip: '画中画',+ icon: const Icon(+ Icons.picture_in_picture,+ color: Colors.white,+ ),+ ),+ // 追番+ CollectButton(+ bangumiItem: videoPageController.bangumiItem,+ onOpen: () {+ widget.cancelHideTimer();+ playerController.canHidePlayerPanel = false;+ },+ onClose: () {+ widget.cancelHideTimer();+ widget.startHideTimer();+ playerController.canHidePlayerPanel = true;+ },+ ),+ MenuAnchor(+ consumeOutsideTap: true,+ onOpen: () {+ widget.cancelHideTimer();+ playerController.canHidePlayerPanel = false;+ },+ onClose: () {+ widget.cancelHideTimer();+ widget.startHideTimer();+ playerController.canHidePlayerPanel = true;+ },+ builder: (BuildContext context, MenuController controller,+ Widget? child) {+ return IconButton(+ onPressed: () {+ if (controller.isOpen) {+ controller.close();+ } else {+ controller.open();}},- tooltip: '画中画',+ tooltip: '更多选项',icon: const Icon(- Icons.picture_in_picture,+ Icons.more_vert,color: Colors.white,),- ),- // 追番- CollectButton(- bangumiItem: videoPageController.bangumiItem,- onOpen: () {- widget.cancelHideTimer();- playerController.canHidePlayerPanel = false;- },- onClose: () {- widget.cancelHideTimer();- widget.startHideTimer();- playerController.canHidePlayerPanel = true;- },- ),- MenuAnchor(- consumeOutsideTap: true,- onOpen: () {- widget.cancelHideTimer();- playerController.canHidePlayerPanel = false;- },- onClose: () {- widget.cancelHideTimer();- widget.startHideTimer();- playerController.canHidePlayerPanel = true;- },- builder: (BuildContext context, MenuController controller,- Widget? child) {- return IconButton(- onPressed: () {- if (controller.isOpen) {- controller.close();- } else {- controller.open();- }- },- tooltip: '更多选项',- icon: const Icon(- Icons.more_vert,- color: Colors.white,+ );+ },+ menuChildren: [+ MenuItemButton(+ onPressed: () {+ widget.showDanmakuSwitch();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("弹幕切换"),),- );- },- menuChildren: [- MenuItemButton(- onPressed: () {- widget.showDanmakuSwitch();- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("弹幕切换"),- ),+ ),+ ),+ MenuItemButton(+ onPressed: () {+ widget.showVideoInfo();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("视频详情"),),),- MenuItemButton(- onPressed: () {- widget.showVideoInfo();- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("视频详情"),- ),+ ),+ MenuItemButton(+ onPressed: () {+ bool needRestart = playerController.playing;+ playerController.pause();+ RemotePlay()+ .castVideo(playerController.videoUrl,+ videoPageController.currentPlugin.referer)+ .whenComplete(() {+ if (needRestart) {+ playerController.play();+ }+ });+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("远程投屏"),),),- MenuItemButton(- onPressed: () {- bool needRestart = playerController.playing;- playerController.pause();- RemotePlay()- .castVideo(playerController.videoUrl,- videoPageController.currentPlugin.referer)- .whenComplete(() {- if (needRestart) {- playerController.play();- }- });- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("远程投屏"),- ),+ ),+ MenuItemButton(+ onPressed: () {+ playerController.lanunchExternalPlayer();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("外部播放"),),),- MenuItemButton(- onPressed: () {- playerController.lanunchExternalPlayer();- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("外部播放"),+ ),+ // 定时关闭+ SubmenuButton(+ menuChildren: [+ MenuItemButton(+ onPressed: () {+ TimedShutdownService().cancel();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text(+ "不开启",+ style: TextStyle(+ color: !TimedShutdownService().isActive+ ? Theme.of(context).colorScheme.primary+ : null,+ ),+ ),+ ),),),- ),- // 定时关闭- SubmenuButton(- menuChildren: [+ for (final int minutes in [15, 30, 60])MenuItemButton(onPressed: () {- TimedShutdownService().cancel();+ TimedShutdownService().start(minutes,+ onExpired: widget.pauseForTimedShutdown);+ KazumiDialog.showToast(+ message:+ '已设置 ${TimedShutdownService().formatMinutesToDisplay(minutes)} 后定时关闭');},child: Container(height: 48,@@ -1270,9 +1298,10 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {child: Align(alignment: Alignment.centerLeft,child: Text(- "不开启",+ "$minutes 分钟",style: TextStyle(- color: !TimedShutdownService().isActive+ color: TimedShutdownService().setMinutes ==+ minutes? Theme.of(context).colorScheme.primary: null,),@@ -1280,185 +1309,162 @@ class _PlayerItemPanelState extends State<PlayerItemPanel> {),),),- for (final int minutes in [15, 30, 60])- MenuItemButton(- onPressed: () {- TimedShutdownService().start(minutes, onExpired: widget.pauseForTimedShutdown);- KazumiDialog.showToast(message: '已设置 ${TimedShutdownService().formatMinutesToDisplay(minutes)} 后定时关闭');- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- "$minutes 分钟",- style: TextStyle(- color: TimedShutdownService().setMinutes == minutes- ? Theme.of(context).colorScheme.primary- : null,- ),- ),- ),- ),+ MenuItemButton(+ onPressed: () {+ TimedShutdownService.showCustomTimerDialog(+ onExpired: widget.pauseForTimedShutdown,+ );+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("自定义"),),- MenuItemButton(- onPressed: () {- TimedShutdownService.showCustomTimerDialog(- onExpired: widget.pauseForTimedShutdown,+ ),+ ),+ ],+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: ValueListenableBuilder<int>(+ valueListenable:+ TimedShutdownService().remainingSecondsNotifier,+ builder: (context, remainingSeconds, child) {+ return Text(+ remainingSeconds > 0+ ? "定时关闭 (${TimedShutdownService().formatRemainingTime()})"+ : "定时关闭",);},- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("自定义"),- ),- ),- ),- ],- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: ValueListenableBuilder<int>(- valueListenable: TimedShutdownService().remainingSecondsNotifier,- builder: (context, remainingSeconds, child) {- return Text(- remainingSeconds > 0- ? "定时关闭 (${TimedShutdownService().formatRemainingTime()})"- : "定时关闭",- );- },- ),),),),- SubmenuButton(- menuChildren: [- MenuItemButton(- child: Container(-- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- "当前房间: ${playerController.syncplayRoom == '' ? '未加入' : playerController.syncplayRoom}"),- ),+ ),+ SubmenuButton(+ menuChildren: [+ MenuItemButton(+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text(+ "当前房间: ${playerController.syncplayRoom == '' ? '未加入' : playerController.syncplayRoom}"),),),- MenuItemButton(- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text(- "网络延时: ${playerController.syncplayClientRtt}ms"),- ),+ ),+ MenuItemButton(+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text(+ "网络延时: ${playerController.syncplayClientRtt}ms"),),),- MenuItemButton(- onPressed: () {- widget.showSyncPlayRoomCreateDialog();- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("加入房间"),- ),+ ),+ MenuItemButton(+ onPressed: () {+ widget.showSyncPlayRoomCreateDialog();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("加入房间"),),),- MenuItemButton(- onPressed: () {- widget.showSyncPlayEndPointSwitchDialog();- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("切换服务器"),- ),+ ),+ MenuItemButton(+ onPressed: () {+ widget.showSyncPlayEndPointSwitchDialog();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("切换服务器"),),),- MenuItemButton(- onPressed: () async {- await playerController.exitSyncPlayRoom();- },- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("断开连接"),- ),+ ),+ MenuItemButton(+ onPressed: () async {+ await playerController.exitSyncPlayRoom();+ },+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("断开连接"),),),- ],- child: Container(- height: 48,- constraints: BoxConstraints(minWidth: 112),- child: Align(- alignment: Alignment.centerLeft,- child: Text("一起看"),- ),+ ),+ ],+ child: Container(+ height: 48,+ constraints: BoxConstraints(minWidth: 112),+ child: Align(+ alignment: Alignment.centerLeft,+ child: Text("一起看"),),),- ],- ),- ],- ),+ ),+ ],+ ),+ ],),),- );- }- );+ ),+ );+ });}Widget get leftControlWidget {- return Observer(- builder: (context) {- return SafeArea(- top: false,- bottom: false,- left: videoPageController.isFullscreen,- right: videoPageController.isFullscreen,- child: Column(- children: [- const Spacer(),- (playerController.lockPanel)- ? Container()- : IconButton(- icon: const Icon(- Icons.photo_camera_outlined,- color: Colors.white,- ),- tooltip: '截图',- onPressed: () {- widget.handleScreenShot();- },+ return Observer(builder: (context) {+ return SafeArea(+ top: false,+ bottom: false,+ left: videoPageController.isFullscreen,+ right: videoPageController.isFullscreen,+ child: Column(+ children: [+ const Spacer(),+ (playerController.lockPanel)+ ? Container()+ : IconButton(+ icon: const Icon(+ Icons.photo_camera_outlined,+ color: Colors.white,),- IconButton(- icon: Icon(- playerController.lockPanel ? Icons.lock_outline : Icons.lock_open,- color: Colors.white,- ),- tooltip: playerController.lockPanel ? '解锁面板' : '锁定面板',- onPressed: () {- playerController.lockPanel = !playerController.lockPanel;- },+ tooltip: '截图',+ onPressed: () {+ widget.handleScreenShot();+ },+ ),+ IconButton(+ icon: Icon(+ playerController.lockPanel+ ? Icons.lock_outline+ : Icons.lock_open,+ color: Colors.white,),- const Spacer(),- ],- ),- );- }- );+ tooltip: playerController.lockPanel ? '解锁面板' : '锁定面板',+ onPressed: () {+ playerController.lockPanel = !playerController.lockPanel;+ },+ ),+ const Spacer(),+ ],+ ),+ );+ });}}diff --git a/lib/pages/player/smallest_player_item_panel.dart b/lib/pages/player/smallest_player_item_panel.dartindex e36337b0..5a808746 100644--- a/lib/pages/player/smallest_player_item_panel.dart+++ b/lib/pages/player/smallest_player_item_panel.dart@@ -79,7 +79,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {Modular.get<VideoPageController>();final PlayerController playerController = Modular.get<PlayerController>();final TextEditingController textController = TextEditingController();-+// SVG CachesString? cachedSvgString;Widget? cachedDanmakuOnIcon;@@ -160,7 +160,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {haEnable = setting.get(SettingBoxKey.hAenable, defaultValue: true);cacheSvgIcons();}-+void cacheSvgIcons() {cachedDanmakuOffIcon = RepaintBoundary(child: SvgPicture.asset(@@ -169,7 +169,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {),);}-+Widget danmakuOnIcon(BuildContext context) {final colorHex = Theme.of(context).colorScheme@@ -213,9 +213,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {},tooltip: playerController.danmakuLoading? '弹幕加载中...'- : (playerController.danmakuOn- ? '关闭弹幕'- : '打开弹幕'),+ : (playerController.danmakuOn ? '关闭弹幕' : '打开弹幕'),);}@@ -240,17 +238,16 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {@overrideWidget build(BuildContext context) {- return Observer(builder: (context) {- return Stack(- alignment: Alignment.center,- children: [- //顶部渐变区域- AnimatedPositioned(- duration: const Duration(seconds: 1),- top: 0,- left: 0,- right: 0,- child: Visibility(+ return Stack(+ alignment: Alignment.center,+ children: [+ AnimatedPositioned(+ duration: const Duration(seconds: 1),+ top: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -285,16 +282,16 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {),),),- ),- ),-- //底部渐变区域- AnimatedPositioned(- duration: const Duration(seconds: 1),- bottom: 0,- left: 0,- right: 0,- child: Visibility(+ );+ }),+ ),+ AnimatedPositioned(+ duration: const Duration(seconds: 1),+ bottom: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -329,12 +326,13 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {),),),- ),- ),- // 顶部进度条- Positioned(- top: 25,- child: playerController.showSeekTime+ );+ }),+ ),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showSeekTime? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -342,7 +340,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: Text(playerController.currentPosition.compareTo(@@ -357,11 +355,12 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {),],)- : Container()),- // 顶部播放速度条- Positioned(- top: 25,- child: playerController.showPlaySpeed+ : Container();+ })),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showPlaySpeed? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -369,7 +368,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: const Row(children: <Widget>[@@ -385,11 +384,12 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {),],)- : Container()),- // 亮度条- Positioned(- top: 25,- child: playerController.showBrightness+ : Container();+ })),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showBrightness? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -397,7 +397,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: Row(children: <Widget>[@@ -413,11 +413,12 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {)),],)- : Container()),- // 音量条- Positioned(- top: 25,- child: playerController.showVolume+ : Container();+ })),+ Positioned(+ top: 25,+ child: Observer(builder: (context) {+ return playerController.showVolume? Wrap(alignment: WrapAlignment.center,children: <Widget>[@@ -425,7 +426,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {padding: const EdgeInsets.all(8.0),decoration: BoxDecoration(color: Colors.black54,- borderRadius: BorderRadius.circular(8.0), // 圆角+ borderRadius: BorderRadius.circular(8.0),),child: Row(children: <Widget>[@@ -441,13 +442,14 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {)),],)- : Container()),- // 自定义顶部组件- Positioned(- top: 0,- left: 0,- right: 0,- child: Visibility(+ : Container();+ })),+ Positioned(+ top: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -456,14 +458,15 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {? topControlWidget: SlideTransition(position: topOffsetAnimation, child: topControlWidget),- ),- ),- // 自定义播放器底部组件- Positioned(- bottom: 0,- left: 0,- right: 0,- child: Visibility(+ );+ }),+ ),+ Positioned(+ bottom: 0,+ left: 0,+ right: 0,+ child: Observer(builder: (context) {+ return Visibility(visible: !playerController.lockPanel &&(widget.disableAnimations? playerController.showVideoController@@ -473,11 +476,11 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {: SlideTransition(position: bottomOffsetAnimation,child: bottomControlWidget),- ),- ),- ],- );- });+ );+ }),+ ),+ ],+ );}Widget get bottomControlWidget {@@ -531,9 +534,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {icon: Icon(videoPageController.isFullscreen? Icons.fullscreen_exit_rounded: Icons.fullscreen_rounded),- tooltip: videoPageController.isFullscreen- ? '退出全屏'- : '全屏',+ tooltip: videoPageController.isFullscreen ? '退出全屏' : '全屏',onPressed: () {widget.handleFullscreen();},@@ -579,7 +580,8 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {videoPageController.isPip = !videoPageController.isPip;return;}- final bool supported = await PipUtils.isAndroidPIPSupported();+ final bool supported =+ await PipUtils.isAndroidPIPSupported();if (!supported) {KazumiDialog.showToast(message: '当前设备不支持画中画');return;@@ -851,8 +853,7 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {context: context,builder: (context) {return DanmakuSettingsSheet(- danmakuController:- playerController.danmakuController,+ danmakuController: playerController.danmakuController,onUpdateDanmakuSpeed:playerController.updateDanmakuSpeed,);@@ -942,8 +943,11 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {for (final int minutes in [15, 30, 60])MenuItemButton(onPressed: () {- TimedShutdownService().start(minutes, onExpired: widget.pauseForTimedShutdown);- KazumiDialog.showToast(message: '已设置 ${TimedShutdownService().formatMinutesToDisplay(minutes)} 后定时关闭');+ TimedShutdownService().start(minutes,+ onExpired: widget.pauseForTimedShutdown);+ KazumiDialog.showToast(+ message:+ '已设置 ${TimedShutdownService().formatMinutesToDisplay(minutes)} 后定时关闭');},child: Container(height: 48,@@ -953,9 +957,10 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {child: Text("$minutes 分钟",style: TextStyle(- color: TimedShutdownService().setMinutes == minutes- ? Theme.of(context).colorScheme.primary- : null,+ color:+ TimedShutdownService().setMinutes == minutes+ ? Theme.of(context).colorScheme.primary+ : null,),),),@@ -983,7 +988,8 @@ class _SmallestPlayerItemPanelState extends State<SmallestPlayerItemPanel> {child: Align(alignment: Alignment.centerLeft,child: ValueListenableBuilder<int>(- valueListenable: TimedShutdownService().remainingSecondsNotifier,+ valueListenable:+ TimedShutdownService().remainingSecondsNotifier,builder: (context, remainingSeconds, child) {return Text(remainingSeconds > 0