Skip to content

Commit

Permalink
Merge pull request jhomlala#114 from jhomlala/feature/november_changes_1
Browse files Browse the repository at this point in the history
Feature/november changes 1
  • Loading branch information
jhomlala authored Nov 1, 2020
2 parents 16e8ebd + 7883d0f commit 5b9aa82
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.31
* Added showPlaceholderUntilPlay in BetterPlayerConfiguration
* Fixed exception event not being triggered
* Fixed controls not displaying on video finished

## 0.0.30
* Fixed issue when full screen was triggered twice if autoPlay and fullScreenByDefault were enabled
* Removed flutter_widgets, since it's not maintained anymore. Added instead visibility_detector package (by https://github.com/espresso3389)
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.30
better_player: ^0.0.31
```
2. Install it
Expand Down Expand Up @@ -265,6 +265,9 @@ Possible configuration options:
/// or played.
final Widget placeholder;
/// Should the placeholder be shown until play is pressed
final bool showPlaceholderUntilPlay;
/// A widget which is placed between the video and the controls
final Widget overlay;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/configuration/better_player_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class BetterPlayerConfiguration {
/// or played.
final Widget placeholder;

/// Should the placeholder be shown until play is pressed
final bool showPlaceholderUntilPlay;

/// A widget which is placed between the video and the controls
final Widget overlay;

Expand Down Expand Up @@ -89,6 +92,7 @@ class BetterPlayerConfiguration {
this.looping = false,
this.fullScreenByDefault = false,
this.placeholder,
this.showPlaceholderUntilPlay = false,
this.overlay,
this.showControlsOnInitialize = true,
this.errorBuilder,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/controls/better_player_cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ class _BetterPlayerCupertinoControlsState
isLoading(_controller.value)) {
setState(() {
_latestValue = _controller.value;
if (isVideoFinished(_latestValue)) {
_hideStuff = false;
}
});
}
}
Expand Down
10 changes: 9 additions & 1 deletion lib/src/controls/better_player_material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ class _BetterPlayerMaterialControlsState
});
} else
cancelAndRestartTimer();
} else {
_onPlayPause();

setState(() {
_hideStuff = true;
});
}
},
);
Expand Down Expand Up @@ -542,6 +548,9 @@ class _BetterPlayerMaterialControlsState
isLoading(_controller.value)) {
setState(() {
_latestValue = _controller.value;
if (isVideoFinished(_latestValue)) {
_hideStuff = false;
}
});
}
}
Expand Down Expand Up @@ -577,7 +586,6 @@ class _BetterPlayerMaterialControlsState
}

Widget _buildLoadingWidget() {
print("Build loading widget");
return CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<Color>(_controlsConfiguration.controlBarColor),
Expand Down
15 changes: 11 additions & 4 deletions lib/src/core/better_player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class BetterPlayerController extends ChangeNotifier {
///Build videoPlayerController if null
if (videoPlayerController == null) {
videoPlayerController = VideoPlayerController();
videoPlayerController.addListener(_onVideoPlayerChanged);
}

///Clear hls tracks
Expand Down Expand Up @@ -230,9 +231,6 @@ class BetterPlayerController extends ChangeNotifier {
if (startAt != null) {
await videoPlayerController.seekTo(startAt);
}

///General purpose listener
videoPlayerController.addListener(_onVideoPlayerChanged);
}

void _fullScreenListener() async {
Expand Down Expand Up @@ -323,10 +321,19 @@ class BetterPlayerController extends ChangeNotifier {
}

void _onVideoPlayerChanged() async {
var currentVideoPlayerValue = videoPlayerController.value;
if (currentVideoPlayerValue.hasError) {
_postEvent(
BetterPlayerEvent(
BetterPlayerEventType.EXCEPTION,
parameters: {"exception": currentVideoPlayerValue.errorDescription},
),
);
}

int now = DateTime.now().millisecondsSinceEpoch;
if (now - _lastPositionSelection > 500) {
_lastPositionSelection = now;
var currentVideoPlayerValue = videoPlayerController.value;
Duration currentPositionShifted = Duration(
milliseconds: currentVideoPlayerValue.position.inMilliseconds + 500);
if (currentPositionShifted == null ||
Expand Down
25 changes: 24 additions & 1 deletion lib/src/core/better_player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';
import 'dart:math';

import 'package:better_player/better_player.dart';
import 'package:better_player/src/controls/better_player_controls_configuration.dart';
import 'package:better_player/src/controls/better_player_cupertino_controls.dart';
import 'package:better_player/src/controls/better_player_material_controls.dart';
Expand Down Expand Up @@ -168,9 +169,24 @@ class _BetterPlayerVideoFitWidgetState

VoidCallback _initializedListener;

bool _started = false;

@override
void initState() {
super.initState();
if (widget.betterPlayerController.betterPlayerConfiguration
.showPlaceholderUntilPlay) {
widget.betterPlayerController.addEventsListener((event) {
if (!_started &&
event.betterPlayerEventType == BetterPlayerEventType.PLAY) {
setState(() {
_started = true;
});
}
});
} else {
_started = true;
}
_initialize();
}

Expand Down Expand Up @@ -200,7 +216,7 @@ class _BetterPlayerVideoFitWidgetState

@override
Widget build(BuildContext context) {
if (_initialized) {
if (_initialized && _started) {
return Center(
child: Container(
width: double.infinity,
Expand All @@ -220,4 +236,11 @@ class _BetterPlayerVideoFitWidgetState
return Container();
}
}

@override
void dispose() {
widget.betterPlayerController.videoPlayerController
.removeListener(_initializedListener);
super.dispose();
}
}
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.30
version: 0.0.31
authors:
- Jakub Homlala <jhomlala@gmail.com>
homepage: https://github.com/jhomlala/betterplayer
Expand Down

0 comments on commit 5b9aa82

Please sign in to comment.