Skip to content

Commit

Permalink
Feature/december changes (#172)
Browse files Browse the repository at this point in the history
* setControlsEnabled implementation

* Updated documentation

* Fixed video list widget buttons not rendering correctly in small resolutions

* Fixed video list widget buttons not rendering correctly in small resolutions

* Added setOverriddenAspectRatio, added example for overriding aspect ratio

* Fixed deviceOrientationsOnFullScreen for iOS

* Fixed crash connected with setSpeed in Android platform

* Fixed default aspect ratio

* Better Player 0.0.37

* Changelog, dartfmt update
  • Loading branch information
jhomlala authored Dec 13, 2020
1 parent 0c15ebe commit c512ae1
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 46 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.0.37
* Added setControlsEnabled to BetterPlayerController
* Fixed example video list widget buttons not rendering correctly in small resolutions
* Added setOverriddenAspectRatio to BetterPlayerController
* Fixed crash connected with setSpeed in Android platform
* Fixed deviceOrientationsOnFullScreen for iOS
* Fixed CH translations (fixes by https://github.com/JarvanMo)
* Click to show/hide controls (fixed by https://github.com/mtAlves)
* [BREAKING_CHANGE] Removed future from isPlaying. Now it's sync method (https://github.com/hongfeiyang)

## 0.0.36
* Added INITIALIZED event
* Added autoDetectFullscreenDeviceOrientation in BetterPlayerConfiguration
Expand Down
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.36
better_player: ^0.0.37
```
2. Install it
Expand Down Expand Up @@ -742,6 +742,17 @@ You can use BetterPlayerControlsConfiguration to add custom element to the overf
),
```

### Enable/disable controls (always hidden if false)
```dart
betterPlayerController.setControlsEnabled(false);
```

### Set overridden aspect ratio. If passed overriddenAspectRatio will be used instead of aspectRatio.
If null then aspectRatio from BetterPlayerConfiguration will be used.
```dart
betterPlayerController.setOverriddenAspectRatio(1.0);
```

### More documentation
https://pub.dev/documentation/better_player/latest/better_player/better_player-library.html

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,8 @@ void setVolume(double value) {

void setSpeed(double value) {
float bracketedValue = (float) value;
PlaybackParameters existingParam = exoPlayer.getPlaybackParameters();
PlaybackParameters newParameter =
new PlaybackParameters(bracketedValue, existingParam.pitch, existingParam.skipSilence);
exoPlayer.setPlaybackParameters(newParameter);
PlaybackParameters playbackParameters = new PlaybackParameters(bracketedValue);
exoPlayer.setPlaybackParameters(playbackParameters);
}

void setTrackParameters(int width, int height, int bitrate) {
Expand Down
11 changes: 11 additions & 0 deletions example/lib/pages/normal_player_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ class _NormalPlayerPageState extends State<NormalPlayerPage> {
BetterPlayerDataSourceType.NETWORK, Constants.forBiggerBlazesUrl);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);

super.initState();
// _betterPlayerController.setControlsEnabled(false);
_betterPlayerController.addEventsListener((event) {
if (event.betterPlayerEventType == BetterPlayerEventType.INITIALIZED) {
_betterPlayerController.setControlsEnabled(false);
}
if (event.betterPlayerEventType ==
BetterPlayerEventType.OPEN_FULLSCREEN) {
_betterPlayerController.setControlsEnabled(true);
}
});
}

@override
Expand Down
53 changes: 53 additions & 0 deletions example/lib/pages/overridden_aspect_ratio_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:better_player/better_player.dart';
import 'package:better_player_example/constants.dart';
import 'package:flutter/material.dart';

class OverriddenAspectRatioPage extends StatefulWidget {
@override
_OverriddenAspectRatioPageState createState() =>
_OverriddenAspectRatioPageState();
}

class _OverriddenAspectRatioPageState extends State<OverriddenAspectRatioPage> {
BetterPlayerController _betterPlayerController;

@override
void initState() {
BetterPlayerConfiguration betterPlayerConfiguration =
BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fit: BoxFit.fill,
);
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.NETWORK, Constants.forBiggerBlazesUrl);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);
_betterPlayerController.setOverriddenAspectRatio(1.0);
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Overridden aspect ratio player"),
),
body: Column(
children: [
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
"Player with different rotation and fit.",
style: TextStyle(fontSize: 16),
),
),
AspectRatio(
aspectRatio: 1.0,
child: BetterPlayer(controller: _betterPlayerController),
),
],
),
);
}
}
46 changes: 24 additions & 22 deletions example/lib/pages/video_list/video_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,30 @@ class _VideoListWidgetState extends State<VideoListWidget> {
"lives? 70's special effects, legendary score, and trademark "
"humor set this classic apart."),
),
Row(children: [
RaisedButton(
child: Text("Play"),
onPressed: () {
controller.play();
},
),
const SizedBox(width: 8),
RaisedButton(
child: Text("Pause"),
onPressed: () {
controller.pause();
},
),
const SizedBox(width: 8),
RaisedButton(
child: Text("Set max volume"),
onPressed: () {
controller.setVolume(100);
},
),
])
Center(
child: Wrap(children: [
RaisedButton(
child: Text("Play"),
onPressed: () {
controller.play();
},
),
const SizedBox(width: 8),
RaisedButton(
child: Text("Pause"),
onPressed: () {
controller.pause();
},
),
const SizedBox(width: 8),
RaisedButton(
child: Text("Set max volume"),
onPressed: () {
controller.setVolume(100);
},
),
]),
),
],
),
);
Expand Down
4 changes: 4 additions & 0 deletions example/lib/pages/welcome_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:better_player_example/pages/hls_subtitles_page.dart';
import 'package:better_player_example/pages/hls_tracks_page.dart';
import 'package:better_player_example/pages/memory_player_page.dart';
import 'package:better_player_example/pages/normal_player_page.dart';
import 'package:better_player_example/pages/overridden_aspect_ratio_page.dart';
import 'package:better_player_example/pages/playlist_page.dart';
import 'package:better_player_example/pages/resolutions_page.dart';
import 'package:better_player_example/pages/rotation_and_fit_page.dart';
Expand Down Expand Up @@ -107,6 +108,9 @@ class _WelcomePageState extends State<WelcomePage> {
_buildExampleElementWidget("Auto fullscreen orientation page", () {
_navigateToPage(AutoFullscreenOrientationPage());
}),
_buildExampleElementWidget("Overridden aspect ratio page", () {
_navigateToPage(OverriddenAspectRatioPage());
}),
];
}

Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ environment:
sdk: ">=2.2.2 <3.0.0"

dependencies:
better_player: any
#better_player:
# path: ../
#better_player: any
better_player:
path: ../
flutter:
sdk: flutter
flutter_localizations:
Expand Down
3 changes: 2 additions & 1 deletion lib/src/controls/better_player_material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class _BetterPlayerMaterialControlsState

AnimatedOpacity _buildBottomBar() {
return AnimatedOpacity(
opacity: _hideStuff ? 0.0 : 1.0,
opacity:
!_betterPlayerController.controlsEnabled || _hideStuff ? 0.0 : 1.0,
duration: _controlsConfiguration.controlsHideTime,
onEnd: _onPlayerHide,
child: Container(
Expand Down
15 changes: 10 additions & 5 deletions lib/src/core/better_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class BetterPlayerState extends State<BetterPlayer>
opaque: true,
);

SystemChrome.setEnabledSystemUIOverlays([]);
await SystemChrome.setEnabledSystemUIOverlays([]);

if (isAndroid) {
if (_betterPlayerConfiguration.autoDetectFullscreenDeviceOrientation ==
Expand All @@ -199,13 +199,18 @@ class BetterPlayerState extends State<BetterPlayer>
DeviceOrientation.landscapeRight
];
}
SystemChrome.setPreferredOrientations(deviceOrientations);
await SystemChrome.setPreferredOrientations(deviceOrientations);
} else {
SystemChrome.setPreferredOrientations(
await SystemChrome.setPreferredOrientations(
widget.controller.betterPlayerConfiguration
.deviceOrientationsOnFullScreen,
);
}
} else {
await SystemChrome.setPreferredOrientations(
widget.controller.betterPlayerConfiguration
.deviceOrientationsOnFullScreen,
);
}

if (!widget.controller.allowedScreenSleep) {
Expand All @@ -220,9 +225,9 @@ class BetterPlayerState extends State<BetterPlayer>
// so we do not need to check Wakelock.isEnabled.
Wakelock.disable();

SystemChrome.setEnabledSystemUIOverlays(
await SystemChrome.setEnabledSystemUIOverlays(
widget.controller.systemOverlaysAfterFullScreen);
SystemChrome.setPreferredOrientations(
await SystemChrome.setPreferredOrientations(
widget.controller.deviceOrientationsAfterFullScreen);
}

Expand Down
31 changes: 29 additions & 2 deletions lib/src/core/better_player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class BetterPlayerController extends ChangeNotifier {
Widget Function(BuildContext context, String errorMessage) get errorBuilder =>
betterPlayerConfiguration.errorBuilder;

double get aspectRatio => betterPlayerConfiguration.aspectRatio;

Widget get placeholder => betterPlayerConfiguration.placeholder;

Widget get overlay => betterPlayerConfiguration.overlay;
Expand Down Expand Up @@ -124,6 +122,12 @@ class BetterPlayerController extends ChangeNotifier {
AppLifecycleState _appLifecycleState = AppLifecycleState.resumed;
BetterPlayerEventType _betterPlayerEventBeforePause;

bool _controlsEnabled = true;

bool get controlsEnabled => _controlsEnabled;

double _overriddenAspectRatio;

BetterPlayerController(
this.betterPlayerConfiguration, {
this.betterPlayerPlaylistConfiguration,
Expand Down Expand Up @@ -374,6 +378,15 @@ class BetterPlayerController extends ChangeNotifier {
_controlsVisibilityStreamController.add(isVisible);
}

///Enable/disable controls (when enabled = false, controls will be always hidden)
void setControlsEnabled(bool enabled) {
assert(enabled != null, "Enabled can't be null");
if (!enabled) {
_controlsVisibilityStreamController.add(false);
}
_controlsEnabled = enabled;
}

///Internal method, used to trigger CONTROLS_VISIBLE or CONTROLS_HIDDEN event
///once controls state changed.
void toggleControlsVisibility(bool isVisible) {
Expand Down Expand Up @@ -569,6 +582,20 @@ class BetterPlayerController extends ChangeNotifier {
}
}

///Setup overridden aspect ratio.
void setOverriddenAspectRatio(double aspectRatio) {
_overriddenAspectRatio = aspectRatio;
}

///Get aspect ratio used in current video. If aspect ratio is null, then
///aspect ratio from BetterPlayerConfiguration will be used. Otherwise
///[_overriddenAspectRatio] will be used.
double getAspectRatio() {
return _overriddenAspectRatio != null
? _overriddenAspectRatio
: betterPlayerConfiguration.aspectRatio;
}

@override
void dispose() {
if (!_disposed) {
Expand Down
8 changes: 5 additions & 3 deletions lib/src/core/better_player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ class _BetterPlayerWithControlsState extends State<BetterPlayerWithControls> {
BetterPlayerUtils.calculateAspectRatio(context);
}
} else {
aspectRatio =
betterPlayerController.betterPlayerConfiguration.aspectRatio ??
BetterPlayerUtils.calculateAspectRatio(context);
aspectRatio = betterPlayerController.getAspectRatio();
}

if (aspectRatio == null) {
aspectRatio = 16 / 9;
}

return Center(
Expand Down
5 changes: 2 additions & 3 deletions lib/src/list/better_player_list_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ class _BetterPlayerListVideoPlayerState
Widget build(BuildContext context) {
super.build(context);
return AspectRatio(
aspectRatio:
_betterPlayerController.betterPlayerConfiguration.aspectRatio ??
BetterPlayerUtils.calculateAspectRatio(context),
aspectRatio: _betterPlayerController.getAspectRatio() ??
BetterPlayerUtils.calculateAspectRatio(context),
child: BetterPlayer(
key: Key("${_getUniqueKey()}_player"),
controller: _betterPlayerController,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/playlist/better_player_playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _BetterPlayerPlaylistState extends State<BetterPlayerPlaylist> {
@override
Widget build(BuildContext context) {
return AspectRatio(
aspectRatio: widget.betterPlayerConfiguration.aspectRatio ??
aspectRatio: _controller.getAspectRatio() ??
BetterPlayerUtils.calculateAspectRatio(context),
child: BetterPlayer(
key: Key(_getKey()),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: better_player
description: Advanced video player based on video_player and Chewie. It's solves many typical use cases and it's easy to run.
version: 0.0.36
version: 0.0.37
authors:
- Jakub Homlala <[email protected]>
homepage: https://github.com/jhomlala/betterplayer
Expand Down

0 comments on commit c512ae1

Please sign in to comment.