Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/december 2021 changes #855

Merged
merged 19 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions docs/controlsconfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
```
8 changes: 8 additions & 0 deletions docs/overriddenfit.md
Original file line number Diff line number Diff line change
@@ -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);
```
11 changes: 11 additions & 0 deletions example/lib/pages/controls_configuration_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ class _ControlsConfigurationPageState extends State<ControlsConfigurationPage> {
aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController),
),
ElevatedButton(
onPressed: () {
setState(() {
_betterPlayerController.setBetterPlayerControlsConfiguration(
BetterPlayerControlsConfiguration(
overflowModalColor: Colors.amberAccent),
);
});
},
child: Text("Reset settings"),
)
],
),
);
Expand Down
5 changes: 5 additions & 0 deletions example/lib/pages/normal_player_page.dart
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,6 +20,10 @@ class _NormalPlayerPageState extends State<NormalPlayerPage> {
fit: BoxFit.contain,
autoPlay: true,
looping: true,
deviceOrientationsAfterFullScreen: [
DeviceOrientation.portraitDown,
DeviceOrientation.portraitUp
],
);
_betterPlayerDataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controls/better_player_cupertino_progress_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
32 changes: 17 additions & 15 deletions lib/src/controls/better_player_material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
),
),
),
Expand Down
32 changes: 32 additions & 0 deletions lib/src/core/better_player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function(BetterPlayerEvent)?> get eventListeners =>
_eventListeners.sublist(1);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -205,6 +215,8 @@ class BetterPlayerController {
this.betterPlayerPlaylistConfiguration,
BetterPlayerDataSource? betterPlayerDataSource,
}) {
this._betterPlayerControlsConfiguration =
betterPlayerConfiguration.controlsConfiguration;
_eventListeners.add(eventListener);
if (betterPlayerDataSource != null) {
setupDataSource(betterPlayerDataSource);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/core/better_player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _BetterPlayerWithControlsState extends State<BetterPlayerWithControls> {
widget.controller!.betterPlayerConfiguration.subtitlesConfiguration;

BetterPlayerControlsConfiguration get controlsConfiguration =>
widget.controller!.betterPlayerConfiguration.controlsConfiguration;
widget.controller!.betterPlayerControlsConfiguration;

final StreamController<bool> playerVisibilityStreamController =
StreamController();
Expand Down Expand Up @@ -134,7 +134,7 @@ class _BetterPlayerWithControlsState extends State<BetterPlayerWithControls> {
angle: rotation * pi / 180,
child: _BetterPlayerVideoFitWidget(
betterPlayerController,
betterPlayerController.betterPlayerConfiguration.fit,
betterPlayerController.getFit(),
),
),
betterPlayerController.betterPlayerConfiguration.overlay ??
Expand Down