From ade5079454ed95427b4c7396b34ffebf3a881c25 Mon Sep 17 00:00:00 2001 From: Mathias Poimer Date: Thu, 27 Feb 2025 12:19:12 +0100 Subject: [PATCH 1/3] Fixed allowMute being ignored on Desktop --- .../material/material_desktop_controls.dart | 68 ++++++------------- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 8141593c8..d5b9d7cf6 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -31,8 +31,7 @@ class MaterialDesktopControls extends StatefulWidget { } } -class _MaterialDesktopControlsState extends State - with SingleTickerProviderStateMixin { +class _MaterialDesktopControlsState extends State with SingleTickerProviderStateMixin { late PlayerNotifier notifier; late VideoPlayerValue _latestValue; double? _latestVolume; @@ -67,14 +66,11 @@ class _MaterialDesktopControlsState extends State void _handleKeyPress(event) { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.space) { _playPause(); - } else if (event is KeyDownEvent && - event.logicalKey == LogicalKeyboardKey.arrowRight) { + } else if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.arrowRight) { _seekForward(); - } else if (event is KeyDownEvent && - event.logicalKey == LogicalKeyboardKey.arrowLeft) { + } else if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.arrowLeft) { _seekBackward(); - } else if (event is KeyDownEvent && - event.logicalKey == LogicalKeyboardKey.escape) { + } else if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.escape) { if (chewieController.isFullScreen) { _onExpandCollapse(); } @@ -127,8 +123,7 @@ class _MaterialDesktopControlsState extends State 0.0, notifier.hideStuff ? barHeight * 0.8 : 0.0, ), - child: _buildSubtitles( - context, chewieController.subtitle!), + child: _buildSubtitles(context, chewieController.subtitle!), ), _buildBottomBar(context), ], @@ -188,13 +183,11 @@ class _MaterialDesktopControlsState extends State _onSpeedButtonTap(); }, iconData: Icons.speed, - title: chewieController.optionsTranslation?.playbackSpeedButtonText ?? - 'Playback speed', + title: chewieController.optionsTranslation?.playbackSpeedButtonText ?? 'Playback speed', ) ]; - if (chewieController.additionalOptions != null && - chewieController.additionalOptions!(context).isNotEmpty) { + if (chewieController.additionalOptions != null && chewieController.additionalOptions!(context).isNotEmpty) { options.addAll(chewieController.additionalOptions!(context)); } @@ -215,8 +208,7 @@ class _MaterialDesktopControlsState extends State useRootNavigator: chewieController.useRootNavigator, builder: (context) => OptionsDialog( options: options, - cancelButtonText: - chewieController.optionsTranslation?.cancelButtonText, + cancelButtonText: chewieController.optionsTranslation?.cancelButtonText, ), ); } @@ -278,8 +270,7 @@ class _MaterialDesktopControlsState extends State duration: const Duration(milliseconds: 300), child: Container( height: barHeight + (chewieController.isFullScreen ? 20.0 : 0), - padding: - EdgeInsets.only(bottom: chewieController.isFullScreen ? 10.0 : 15), + padding: EdgeInsets.only(bottom: chewieController.isFullScreen ? 10.0 : 15), child: SafeArea( bottom: chewieController.isFullScreen, child: Column( @@ -291,18 +282,12 @@ class _MaterialDesktopControlsState extends State child: Row( children: [ _buildPlayPause(controller), - _buildMuteButton(controller), - if (chewieController.isLive) - const Expanded(child: Text('LIVE')) - else - _buildPosition(iconColor), + if (chewieController.allowMuting) _buildMuteButton(controller), + if (chewieController.isLive) const Expanded(child: Text('LIVE')) else _buildPosition(iconColor), const Spacer(), - if (chewieController.showControls && - chewieController.subtitle != null && - chewieController.subtitle!.isNotEmpty) + if (chewieController.showControls && chewieController.subtitle != null && chewieController.subtitle!.isNotEmpty) _buildSubtitleToggle(icon: Icons.subtitles), - if (chewieController.showOptions) - _buildOptionsButton(icon: Icons.settings), + if (chewieController.showOptions) _buildOptionsButton(icon: Icons.settings), if (chewieController.allowFullScreen) _buildExpandButton(), ], ), @@ -344,9 +329,7 @@ class _MaterialDesktopControlsState extends State ), child: Center( child: Icon( - chewieController.isFullScreen - ? Icons.fullscreen_exit - : Icons.fullscreen, + chewieController.isFullScreen ? Icons.fullscreen_exit : Icons.fullscreen, color: Colors.white, ), ), @@ -356,10 +339,8 @@ class _MaterialDesktopControlsState extends State } Widget _buildHitArea() { - final bool isFinished = _latestValue.position >= _latestValue.duration && - _latestValue.duration.inSeconds > 0; - final bool showPlayButton = - widget.showPlayButton && !_dragging && !notifier.hideStuff; + final bool isFinished = _latestValue.position >= _latestValue.duration && _latestValue.duration.inSeconds > 0; + final bool showPlayButton = widget.showPlayButton && !_dragging && !notifier.hideStuff; return GestureDetector( onTap: () { @@ -494,8 +475,7 @@ class _MaterialDesktopControlsState extends State } Future _initialize() async { - _subtitleOn = chewieController.showSubtitles && - (chewieController.subtitle?.isNotEmpty ?? false); + _subtitleOn = chewieController.showSubtitles && (chewieController.subtitle?.isNotEmpty ?? false); controller.addListener(_updateState); _updateState(); @@ -520,8 +500,7 @@ class _MaterialDesktopControlsState extends State chewieController.toggleFullScreen(); - _showAfterExpandCollapseTimer = - Timer(const Duration(milliseconds: 300), () { + _showAfterExpandCollapseTimer = Timer(const Duration(milliseconds: 300), () { setState(() { _cancelAndRestartTimer(); }); @@ -552,9 +531,8 @@ class _MaterialDesktopControlsState extends State } void _startHideTimer() { - final hideControlsTimer = chewieController.hideControlsTimer.isNegative - ? ChewieController.defaultHideControlsTimer - : chewieController.hideControlsTimer; + final hideControlsTimer = + chewieController.hideControlsTimer.isNegative ? ChewieController.defaultHideControlsTimer : chewieController.hideControlsTimer; _hideTimer = Timer(hideControlsTimer, () { setState(() { notifier.hideStuff = true; @@ -649,10 +627,8 @@ class _MaterialDesktopControlsState extends State ChewieProgressColors( playedColor: Theme.of(context).colorScheme.secondary, handleColor: Theme.of(context).colorScheme.secondary, - bufferedColor: - Theme.of(context).colorScheme.surface.withOpacityCompat(0.5), - backgroundColor: - Theme.of(context).disabledColor.withOpacityCompat(0.5), + bufferedColor: Theme.of(context).colorScheme.surface.withOpacityCompat(0.5), + backgroundColor: Theme.of(context).disabledColor.withOpacityCompat(0.5), ), draggableProgressBar: chewieController.draggableProgressBar, ), From 4da460ad10e13c8e6c966da525a57ef709be2700 Mon Sep 17 00:00:00 2001 From: Mathias Poimer Date: Fri, 14 Mar 2025 09:18:17 +0100 Subject: [PATCH 2/3] reverted formatting --- .../material/material_desktop_controls.dart | 69 +++++++++++++------ 1 file changed, 47 insertions(+), 22 deletions(-) diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index d5b9d7cf6..04ccfdab7 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -31,7 +31,8 @@ class MaterialDesktopControls extends StatefulWidget { } } -class _MaterialDesktopControlsState extends State with SingleTickerProviderStateMixin { +class _MaterialDesktopControlsState extends State + with SingleTickerProviderStateMixin { late PlayerNotifier notifier; late VideoPlayerValue _latestValue; double? _latestVolume; @@ -66,11 +67,14 @@ class _MaterialDesktopControlsState extends State with void _handleKeyPress(event) { if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.space) { _playPause(); - } else if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.arrowRight) { + } else if (event is KeyDownEvent && + event.logicalKey == LogicalKeyboardKey.arrowRight) { _seekForward(); - } else if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.arrowLeft) { + } else if (event is KeyDownEvent && + event.logicalKey == LogicalKeyboardKey.arrowLeft) { _seekBackward(); - } else if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.escape) { + } else if (event is KeyDownEvent && + event.logicalKey == LogicalKeyboardKey.escape) { if (chewieController.isFullScreen) { _onExpandCollapse(); } @@ -123,7 +127,8 @@ class _MaterialDesktopControlsState extends State with 0.0, notifier.hideStuff ? barHeight * 0.8 : 0.0, ), - child: _buildSubtitles(context, chewieController.subtitle!), + child: _buildSubtitles( + context, chewieController.subtitle!), ), _buildBottomBar(context), ], @@ -183,11 +188,13 @@ class _MaterialDesktopControlsState extends State with _onSpeedButtonTap(); }, iconData: Icons.speed, - title: chewieController.optionsTranslation?.playbackSpeedButtonText ?? 'Playback speed', + title: chewieController.optionsTranslation?.playbackSpeedButtonText ?? + 'Playback speed', ) ]; - if (chewieController.additionalOptions != null && chewieController.additionalOptions!(context).isNotEmpty) { + if (chewieController.additionalOptions != null && + chewieController.additionalOptions!(context).isNotEmpty) { options.addAll(chewieController.additionalOptions!(context)); } @@ -208,7 +215,8 @@ class _MaterialDesktopControlsState extends State with useRootNavigator: chewieController.useRootNavigator, builder: (context) => OptionsDialog( options: options, - cancelButtonText: chewieController.optionsTranslation?.cancelButtonText, + cancelButtonText: + chewieController.optionsTranslation?.cancelButtonText, ), ); } @@ -270,7 +278,8 @@ class _MaterialDesktopControlsState extends State with duration: const Duration(milliseconds: 300), child: Container( height: barHeight + (chewieController.isFullScreen ? 20.0 : 0), - padding: EdgeInsets.only(bottom: chewieController.isFullScreen ? 10.0 : 15), + padding: + EdgeInsets.only(bottom: chewieController.isFullScreen ? 10.0 : 15), child: SafeArea( bottom: chewieController.isFullScreen, child: Column( @@ -282,12 +291,19 @@ class _MaterialDesktopControlsState extends State with child: Row( children: [ _buildPlayPause(controller), - if (chewieController.allowMuting) _buildMuteButton(controller), - if (chewieController.isLive) const Expanded(child: Text('LIVE')) else _buildPosition(iconColor), + if (chewieController.allowMuting) + _buildMuteButton(controller), + if (chewieController.isLive) + const Expanded(child: Text('LIVE')) + else + _buildPosition(iconColor), const Spacer(), - if (chewieController.showControls && chewieController.subtitle != null && chewieController.subtitle!.isNotEmpty) + if (chewieController.showControls && + chewieController.subtitle != null && + chewieController.subtitle!.isNotEmpty) _buildSubtitleToggle(icon: Icons.subtitles), - if (chewieController.showOptions) _buildOptionsButton(icon: Icons.settings), + if (chewieController.showOptions) + _buildOptionsButton(icon: Icons.settings), if (chewieController.allowFullScreen) _buildExpandButton(), ], ), @@ -329,7 +345,9 @@ class _MaterialDesktopControlsState extends State with ), child: Center( child: Icon( - chewieController.isFullScreen ? Icons.fullscreen_exit : Icons.fullscreen, + chewieController.isFullScreen + ? Icons.fullscreen_exit + : Icons.fullscreen, color: Colors.white, ), ), @@ -339,8 +357,10 @@ class _MaterialDesktopControlsState extends State with } Widget _buildHitArea() { - final bool isFinished = _latestValue.position >= _latestValue.duration && _latestValue.duration.inSeconds > 0; - final bool showPlayButton = widget.showPlayButton && !_dragging && !notifier.hideStuff; + final bool isFinished = _latestValue.position >= _latestValue.duration && + _latestValue.duration.inSeconds > 0; + final bool showPlayButton = + widget.showPlayButton && !_dragging && !notifier.hideStuff; return GestureDetector( onTap: () { @@ -475,7 +495,8 @@ class _MaterialDesktopControlsState extends State with } Future _initialize() async { - _subtitleOn = chewieController.showSubtitles && (chewieController.subtitle?.isNotEmpty ?? false); + _subtitleOn = chewieController.showSubtitles && + (chewieController.subtitle?.isNotEmpty ?? false); controller.addListener(_updateState); _updateState(); @@ -500,7 +521,8 @@ class _MaterialDesktopControlsState extends State with chewieController.toggleFullScreen(); - _showAfterExpandCollapseTimer = Timer(const Duration(milliseconds: 300), () { + _showAfterExpandCollapseTimer = + Timer(const Duration(milliseconds: 300), () { setState(() { _cancelAndRestartTimer(); }); @@ -531,8 +553,9 @@ class _MaterialDesktopControlsState extends State with } void _startHideTimer() { - final hideControlsTimer = - chewieController.hideControlsTimer.isNegative ? ChewieController.defaultHideControlsTimer : chewieController.hideControlsTimer; + final hideControlsTimer = chewieController.hideControlsTimer.isNegative + ? ChewieController.defaultHideControlsTimer + : chewieController.hideControlsTimer; _hideTimer = Timer(hideControlsTimer, () { setState(() { notifier.hideStuff = true; @@ -627,8 +650,10 @@ class _MaterialDesktopControlsState extends State with ChewieProgressColors( playedColor: Theme.of(context).colorScheme.secondary, handleColor: Theme.of(context).colorScheme.secondary, - bufferedColor: Theme.of(context).colorScheme.surface.withOpacityCompat(0.5), - backgroundColor: Theme.of(context).disabledColor.withOpacityCompat(0.5), + bufferedColor: + Theme.of(context).colorScheme.surface.withOpacityCompat(0.5), + backgroundColor: + Theme.of(context).disabledColor.withOpacityCompat(0.5), ), draggableProgressBar: chewieController.draggableProgressBar, ), From 2aca16ec9b6e46d7dcb830df0567133a76a9073e Mon Sep 17 00:00:00 2001 From: Mathias Poimer Date: Thu, 27 Mar 2025 19:24:00 +0100 Subject: [PATCH 3/3] formatted with dart 3.27 --- lib/src/material/material_desktop_controls.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/material/material_desktop_controls.dart b/lib/src/material/material_desktop_controls.dart index 04ccfdab7..91d4afeaa 100644 --- a/lib/src/material/material_desktop_controls.dart +++ b/lib/src/material/material_desktop_controls.dart @@ -291,7 +291,7 @@ class _MaterialDesktopControlsState extends State child: Row( children: [ _buildPlayPause(controller), - if (chewieController.allowMuting) + if (chewieController.allowMuting) _buildMuteButton(controller), if (chewieController.isLive) const Expanded(child: Text('LIVE'))