diff --git a/CHANGELOG.md b/CHANGELOG.md index 34902e655..e877ccd58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.0.81 +* Fixed full screen button padding in material controls. +* Added `setBetterPlayerControlsConfiguration` in `BetterPlayerController`. +* Added `setOverriddenFit` in `BetterPlayerController`. + ## 0.0.80 * Removed pedantic dependency. * Updated dependencies. diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 6838376a7..1bc3c1434 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -24,6 +24,7 @@ * [Custom element in overflow menu](customelementinoverflowmenu.md) * [Enable/disable controls](enabledisablecontrols.md) * [Overridden aspect ratio](overriddenaspectratio.md) + * [Overridden fit](overriddenfit.md) * [Overriden duration](overriddenduration.md) * [Mix audio with others](mixaudiowithothers.md) * [Manual dispose](manualdispose.md) diff --git a/docs/controlsconfiguration.md b/docs/controlsconfiguration.md index 33651b5f7..b785d9d86 100644 --- a/docs/controlsconfiguration.md +++ b/docs/controlsconfiguration.md @@ -163,4 +163,13 @@ final double sigmaX; ///Quality of Gaussian Blur for y (iOS only). final double sigmaY; +``` + +You can change controls configuration in runtime with `setBetterPlayerControlsConfiguration` method of `BetterPlayerController`. + +```dart + _betterPlayerController.setBetterPlayerControlsConfiguration( + BetterPlayerControlsConfiguration( + overflowModalColor: Colors.amberAccent), + ); ``` \ No newline at end of file diff --git a/docs/overriddenfit.md b/docs/overriddenfit.md new file mode 100644 index 000000000..99b5095a3 --- /dev/null +++ b/docs/overriddenfit.md @@ -0,0 +1,8 @@ +## Overriden aspect ratio + +You can override `BetterPlayerConfiguration`'s `fit` parameter in runtime with `setOverridenFit` +method from `betterPlayerController`. + +```dart +betterPlayerController.setOverriddenFit(BoxFit.contain); +``` \ No newline at end of file diff --git a/example/lib/pages/controls_configuration_page.dart b/example/lib/pages/controls_configuration_page.dart index a12c1815a..c3d650010 100644 --- a/example/lib/pages/controls_configuration_page.dart +++ b/example/lib/pages/controls_configuration_page.dart @@ -61,6 +61,17 @@ class _ControlsConfigurationPageState extends State { aspectRatio: 16 / 9, child: BetterPlayer(controller: _betterPlayerController), ), + ElevatedButton( + onPressed: () { + setState(() { + _betterPlayerController.setBetterPlayerControlsConfiguration( + BetterPlayerControlsConfiguration( + overflowModalColor: Colors.amberAccent), + ); + }); + }, + child: Text("Reset settings"), + ) ], ), ); diff --git a/example/lib/pages/normal_player_page.dart b/example/lib/pages/normal_player_page.dart index 8ea1f2701..076107f0d 100644 --- a/example/lib/pages/normal_player_page.dart +++ b/example/lib/pages/normal_player_page.dart @@ -1,6 +1,7 @@ import 'package:better_player/better_player.dart'; import 'package:better_player_example/constants.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; class NormalPlayerPage extends StatefulWidget { @override @@ -19,6 +20,10 @@ class _NormalPlayerPageState extends State { fit: BoxFit.contain, autoPlay: true, looping: true, + deviceOrientationsAfterFullScreen: [ + DeviceOrientation.portraitDown, + DeviceOrientation.portraitUp + ], ); _betterPlayerDataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, diff --git a/lib/src/controls/better_player_cupertino_progress_bar.dart b/lib/src/controls/better_player_cupertino_progress_bar.dart index b0a9107b1..713cb37c9 100644 --- a/lib/src/controls/better_player_cupertino_progress_bar.dart +++ b/lib/src/controls/better_player_cupertino_progress_bar.dart @@ -68,7 +68,7 @@ class _VideoProgressBarState @override Widget build(BuildContext context) { final bool enableProgressBarDrag = betterPlayerController! - .betterPlayerConfiguration.controlsConfiguration.enableProgressBarDrag; + .betterPlayerControlsConfiguration.enableProgressBarDrag; return GestureDetector( onHorizontalDragStart: (DragStartDetails details) { if (!controller!.value.initialized || !enableProgressBarDrag) { diff --git a/lib/src/controls/better_player_material_controls.dart b/lib/src/controls/better_player_material_controls.dart index 90bc945ad..a018854bb 100644 --- a/lib/src/controls/better_player_material_controls.dart +++ b/lib/src/controls/better_player_material_controls.dart @@ -334,21 +334,23 @@ class _BetterPlayerMaterialControlsState } Widget _buildExpandButton() { - return BetterPlayerMaterialClickableWidget( - onTap: _onExpandCollapse, - child: AnimatedOpacity( - opacity: controlsNotVisible ? 0.0 : 1.0, - duration: _controlsConfiguration.controlsHideTime, - child: Container( - height: _controlsConfiguration.controlBarHeight, - margin: const EdgeInsets.only(right: 12.0), - padding: const EdgeInsets.symmetric(horizontal: 8.0), - child: Center( - child: Icon( - _betterPlayerController!.isFullScreen - ? _controlsConfiguration.fullscreenDisableIcon - : _controlsConfiguration.fullscreenEnableIcon, - color: _controlsConfiguration.iconsColor, + return Padding( + padding: EdgeInsets.only(right: 12.0), + child: BetterPlayerMaterialClickableWidget( + onTap: _onExpandCollapse, + child: AnimatedOpacity( + opacity: controlsNotVisible ? 0.0 : 1.0, + duration: _controlsConfiguration.controlsHideTime, + child: Container( + height: _controlsConfiguration.controlBarHeight, + padding: const EdgeInsets.symmetric(horizontal: 8.0), + child: Center( + child: Icon( + _betterPlayerController!.isFullScreen + ? _controlsConfiguration.fullscreenDisableIcon + : _controlsConfiguration.fullscreenEnableIcon, + color: _controlsConfiguration.iconsColor, + ), ), ), ), diff --git a/lib/src/core/better_player_controller.dart b/lib/src/core/better_player_controller.dart index 50b72f64a..d1a53bc31 100644 --- a/lib/src/core/better_player_controller.dart +++ b/lib/src/core/better_player_controller.dart @@ -42,6 +42,13 @@ class BetterPlayerController { ///between flutter high level code and lower level native code. VideoPlayerController? videoPlayerController; + ///Controls configuration + late BetterPlayerControlsConfiguration _betterPlayerControlsConfiguration; + + ///Controls configuration + BetterPlayerControlsConfiguration get betterPlayerControlsConfiguration => + _betterPlayerControlsConfiguration; + ///Expose all active eventListeners List get eventListeners => _eventListeners.sublist(1); @@ -139,6 +146,9 @@ class BetterPlayerController { ///in configuration. double? _overriddenAspectRatio; + ///Overridden fit which will be used instead of fit passed in configuration. + BoxFit? _overriddenFit; + ///Was Picture in Picture opened. bool _wasInPipMode = false; @@ -205,6 +215,8 @@ class BetterPlayerController { this.betterPlayerPlaylistConfiguration, BetterPlayerDataSource? betterPlayerDataSource, }) { + this._betterPlayerControlsConfiguration = + betterPlayerConfiguration.controlsConfiguration; _eventListeners.add(eventListener); if (betterPlayerDataSource != null) { setupDataSource(betterPlayerDataSource); @@ -1027,6 +1039,19 @@ class BetterPlayerController { return _overriddenAspectRatio ?? betterPlayerConfiguration.aspectRatio; } + // ignore: use_setters_to_change_properties + ///Setup overridden fit. + void setOverriddenFit(BoxFit fit) { + _overriddenFit = fit; + } + + ///Get fit used in current video. If fit is null, then fit from + ///BetterPlayerConfiguration will be used. Otherwise [_overriddenFit] will be + ///used. + BoxFit getFit() { + return _overriddenFit ?? betterPlayerConfiguration.fit; + } + ///Enable Picture in Picture (PiP) mode. [betterPlayerGlobalKey] is required ///to open PiP mode in iOS. When device is not supported, PiP mode won't be ///open. @@ -1239,6 +1264,13 @@ class BetterPlayerController { betterPlayerDataSource.cacheConfiguration?.key); } + /// Sets the new [betterPlayerControlsConfiguration] instance in the + /// controller. + void setBetterPlayerControlsConfiguration( + BetterPlayerControlsConfiguration betterPlayerControlsConfiguration) { + this._betterPlayerControlsConfiguration = betterPlayerControlsConfiguration; + } + /// Add controller internal event. void _postControllerEvent(BetterPlayerControllerEvent event) { if (!_controllerEventStreamController.isClosed) { diff --git a/lib/src/core/better_player_with_controls.dart b/lib/src/core/better_player_with_controls.dart index abeb328b0..49c91f94e 100644 --- a/lib/src/core/better_player_with_controls.dart +++ b/lib/src/core/better_player_with_controls.dart @@ -25,7 +25,7 @@ class _BetterPlayerWithControlsState extends State { widget.controller!.betterPlayerConfiguration.subtitlesConfiguration; BetterPlayerControlsConfiguration get controlsConfiguration => - widget.controller!.betterPlayerConfiguration.controlsConfiguration; + widget.controller!.betterPlayerControlsConfiguration; final StreamController playerVisibilityStreamController = StreamController(); @@ -134,7 +134,7 @@ class _BetterPlayerWithControlsState extends State { angle: rotation * pi / 180, child: _BetterPlayerVideoFitWidget( betterPlayerController, - betterPlayerController.betterPlayerConfiguration.fit, + betterPlayerController.getFit(), ), ), betterPlayerController.betterPlayerConfiguration.overlay ??