Skip to content

Commit

Permalink
Feature/december changes 3 (#186)
Browse files Browse the repository at this point in the history
* Fixed cupertino loadingColor and loadingWidget issue, fixed cupertino buttons height

* Fixed setControlsEnabled in cupertino player

* General cleanup
  • Loading branch information
jhomlala authored Dec 28, 2020
1 parent a0150b4 commit bd94979
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 57 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.0.41
* Fixed loadingColor and loadingWidget for cupertino player
* Increased size of cupertino buttons
* Fixed setControlsEnabled in cupertino/material player
* [BREAKING_CHANGE] Removed startAt, looping, placeholder, overlay, fullScreenByDefault,
allowedScreenSleep, systemOverlaysAfterFullScreen, deviceOrientationsAfterFullScreen from BetterPlayerController


## 0.0.40
* Exposed VideoPlayerValue in export
* Fixed log issue
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.40
better_player: ^0.0.41
```
2. Install it
Expand Down
4 changes: 1 addition & 3 deletions example/lib/pages/normal_player_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ class _NormalPlayerPageState extends State<NormalPlayerPage> {
fit: BoxFit.contain,
);
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
"https://v5.szjal.cn/20200829/qByymCNH/index.m3u8");
BetterPlayerDataSourceType.network, Constants.elephantDreamVideoUrl);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);

super.initState();
}

Expand Down
23 changes: 14 additions & 9 deletions lib/src/controls/better_player_cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ class _BetterPlayerCupertinoControlsState
super.didChangeDependencies();
}

AnimatedOpacity _buildBottomBar(
Widget _buildBottomBar(
Color backgroundColor,
Color iconColor,
double barHeight,
) {
if (!betterPlayerController.controlsEnabled) {
return const SizedBox();
}
return AnimatedOpacity(
opacity: _hideStuff ? 0.0 : 1.0,
duration: _controlsConfiguration.controlsHideTime,
Expand Down Expand Up @@ -254,7 +257,6 @@ class _BetterPlayerCupertinoControlsState
? _controlsConfiguration.fullscreenDisableIcon
: _controlsConfiguration.fullscreenEnableIcon,
color: iconColor,
size: 12.0,
),
),
),
Expand Down Expand Up @@ -321,7 +323,6 @@ class _BetterPlayerCupertinoControlsState
child: Icon(
_controlsConfiguration.overflowMenuIcon,
color: iconColor,
size: 16.0,
),
),
),
Expand Down Expand Up @@ -368,7 +369,6 @@ class _BetterPlayerCupertinoControlsState
? _controlsConfiguration.muteIcon
: _controlsConfiguration.unMuteIcon,
color: iconColor,
size: 16.0,
),
),
),
Expand All @@ -394,7 +394,6 @@ class _BetterPlayerCupertinoControlsState
? _controlsConfiguration.pauseIcon
: _controlsConfiguration.playIcon,
color: iconColor,
size: 16.0,
),
),
);
Expand Down Expand Up @@ -442,7 +441,6 @@ class _BetterPlayerCupertinoControlsState
child: Icon(
_controlsConfiguration.skipBackIcon,
color: iconColor,
size: 12.0,
),
),
);
Expand All @@ -459,7 +457,6 @@ class _BetterPlayerCupertinoControlsState
child: Icon(
_controlsConfiguration.skipForwardIcon,
color: iconColor,
size: 12.0,
),
),
);
Expand All @@ -471,6 +468,10 @@ class _BetterPlayerCupertinoControlsState
double barHeight,
double buttonPadding,
) {
if (!betterPlayerController.controlsEnabled) {
return const SizedBox();
}

return Container(
height: barHeight,
margin: EdgeInsets.only(
Expand Down Expand Up @@ -700,10 +701,14 @@ class _BetterPlayerCupertinoControlsState
}

Widget _buildLoadingWidget() {
if (_controlsConfiguration.loadingWidget != null) {
return _controlsConfiguration.loadingWidget;
}

return CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
_controlsConfiguration.controlBarColor,
),
_controlsConfiguration.loadingColor ??
_controlsConfiguration.controlBarColor),
);
}
}
25 changes: 17 additions & 8 deletions lib/src/controls/better_player_material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class BetterPlayerMaterialControls extends StatefulWidget {
///Controls config
final BetterPlayerControlsConfiguration controlsConfiguration;

const BetterPlayerMaterialControls(
{Key key,
@required this.onControlsVisibilityChanged,
@required this.controlsConfiguration})
: assert(onControlsVisibilityChanged != null),
const BetterPlayerMaterialControls({
Key key,
@required this.onControlsVisibilityChanged,
@required this.controlsConfiguration,
}) : assert(onControlsVisibilityChanged != null),
assert(controlsConfiguration != null),
super(key: key);

Expand Down Expand Up @@ -156,6 +156,10 @@ class _BetterPlayerMaterialControlsState
}

Widget _buildTopBar() {
if (!betterPlayerController.controlsEnabled) {
return const SizedBox();
}

return _controlsConfiguration.enableOverflowMenu
? AnimatedOpacity(
opacity: _hideStuff ? 0.0 : 1.0,
Expand Down Expand Up @@ -189,10 +193,12 @@ class _BetterPlayerMaterialControlsState
);
}

AnimatedOpacity _buildBottomBar() {
Widget _buildBottomBar() {
if (!betterPlayerController.controlsEnabled) {
return const SizedBox();
}
return AnimatedOpacity(
opacity:
!_betterPlayerController.controlsEnabled || _hideStuff ? 0.0 : 1.0,
opacity: _hideStuff ? 0.0 : 1.0,
duration: _controlsConfiguration.controlsHideTime,
onEnd: _onPlayerHide,
child: Container(
Expand Down Expand Up @@ -265,6 +271,9 @@ class _BetterPlayerMaterialControlsState
}

Widget _buildHitArea() {
if (!betterPlayerController.controlsEnabled) {
return const SizedBox();
}
return Expanded(
child: Container(
color: Colors.transparent,
Expand Down
6 changes: 3 additions & 3 deletions lib/src/core/better_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class BetterPlayerState extends State<BetterPlayer>
);
}

if (!widget.controller.allowedScreenSleep) {
if (!_betterPlayerConfiguration.allowedScreenSleep) {
Wakelock.enable();
}

Expand All @@ -231,9 +231,9 @@ class BetterPlayerState extends State<BetterPlayer>
Wakelock.disable();

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

Widget _buildPlayer() {
Expand Down
40 changes: 10 additions & 30 deletions lib/src/core/better_player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:io';
// Flutter imports:
import 'package:better_player/src/core/better_player_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

// Package imports:
import 'package:path_provider/path_provider.dart';
Expand All @@ -32,32 +31,21 @@ class BetterPlayerController extends ChangeNotifier {

final BetterPlayerConfiguration betterPlayerConfiguration;
final BetterPlayerPlaylistConfiguration betterPlayerPlaylistConfiguration;
final List<Function> _eventListeners = [];
final List<BetterPlayerSubtitlesSource> _betterPlayerSubtitlesSourceList = [];

///List of files to delete once player disposes.
final List<File> _tempFiles = [];
final StreamController<bool> _controlsVisibilityStreamController =
StreamController.broadcast();

VideoPlayerController videoPlayerController;

bool get autoPlay => betterPlayerConfiguration.autoPlay;

Duration get startAt => betterPlayerConfiguration.startAt;

bool get looping => betterPlayerConfiguration.looping;

Widget Function(BuildContext context, String errorMessage) get errorBuilder =>
betterPlayerConfiguration.errorBuilder;

Widget get placeholder => betterPlayerConfiguration.placeholder;

Widget get overlay => betterPlayerConfiguration.overlay;

bool get fullScreenByDefault => betterPlayerConfiguration.fullScreenByDefault;

bool get allowedScreenSleep => betterPlayerConfiguration.allowedScreenSleep;

List<SystemUiOverlay> get systemOverlaysAfterFullScreen =>
betterPlayerConfiguration.systemOverlaysAfterFullScreen;

List<DeviceOrientation> get deviceOrientationsAfterFullScreen =>
betterPlayerConfiguration.deviceOrientationsAfterFullScreen;

/// Defines a event listener where video player events will be send
Function(BetterPlayerEvent) get eventListener =>
betterPlayerConfiguration.eventListener;
Expand All @@ -68,14 +56,10 @@ class BetterPlayerController extends ChangeNotifier {

int _lastPositionSelection = 0;

final List<Function> _eventListeners = [];

BetterPlayerDataSource _betterPlayerDataSource;

BetterPlayerDataSource get betterPlayerDataSource => _betterPlayerDataSource;

final List<BetterPlayerSubtitlesSource> _betterPlayerSubtitlesSourceList = [];

List<BetterPlayerSubtitlesSource> get betterPlayerSubtitlesSourceList =>
_betterPlayerSubtitlesSourceList;
BetterPlayerSubtitlesSource _betterPlayerSubtitlesSource;
Expand Down Expand Up @@ -110,18 +94,12 @@ class BetterPlayerController extends ChangeNotifier {
///Currently used translations
BetterPlayerTranslations translations = BetterPlayerTranslations();

///List of files to delete once player disposes.
final List<File> _tempFiles = [];

///Has current data source started
bool _hasCurrentDataSourceStarted = false;

///Has current data source initialized
bool _hasCurrentDataSourceInitialized = false;

final StreamController<bool> _controlsVisibilityStreamController =
StreamController.broadcast();

///Stream which sends flag whenever visibility of controls changes
Stream<bool> get controlsVisibilityStream =>
_controlsVisibilityStreamController.stream;
Expand Down Expand Up @@ -307,8 +285,9 @@ class BetterPlayerController extends ChangeNotifier {
}

Future _initialize() async {
await videoPlayerController.setLooping(looping);
await videoPlayerController.setLooping(betterPlayerConfiguration.looping);

final fullScreenByDefault = betterPlayerConfiguration.fullScreenByDefault;
if (autoPlay) {
if (fullScreenByDefault) {
enterFullScreen();
Expand All @@ -321,6 +300,7 @@ class BetterPlayerController extends ChangeNotifier {
}
}

final startAt = betterPlayerConfiguration.startAt;
if (startAt != null) {
await videoPlayerController.seekTo(startAt);
}
Expand Down
6 changes: 4 additions & 2 deletions lib/src/core/better_player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,17 @@ class _BetterPlayerWithControlsState extends State<BetterPlayerWithControls> {
child: Stack(
fit: StackFit.passthrough,
children: <Widget>[
betterPlayerController.placeholder ?? Container(),
betterPlayerController.betterPlayerConfiguration.placeholder ??
Container(),
Transform.rotate(
angle: rotation * pi / 180,
child: _BetterPlayerVideoFitWidget(
betterPlayerController,
betterPlayerController.betterPlayerConfiguration.fit,
),
),
betterPlayerController.overlay ?? Container(),
betterPlayerController.betterPlayerConfiguration.overlay ??
Container(),
BetterPlayerSubtitlesDrawer(
betterPlayerController: betterPlayerController,
betterPlayerSubtitlesConfiguration: subtitlesConfiguration,
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.40
version: 0.0.41
authors:
- Jakub Homlala <[email protected]>
homepage: https://github.com/jhomlala/betterplayer
Expand Down

0 comments on commit bd94979

Please sign in to comment.