Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmadre authored Nov 25, 2021
2 parents 103e23b + e9ba734 commit 67bf9fc
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 135 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
## 1.2.3

* ⬆️ Update 'provider' to 6.0.1
* ⬆️ Update 'video_player' to 2.2.5
- fixes [#568](https://github.com/brianegan/chewie/issues/568)
* ⬆️ Update 'video_player' to 2.2.7
* ⬆️ Update 'wakelock' to 0.5.6
* ⬆️ Update 'lint' to 1.7.2
* ⬆️ Update roadmap
* 🛠️ Fix lint problems
* 💡 Add very_good_analysis package
* 💡 Add analysis_options.yaml for example app
Expand Down
32 changes: 26 additions & 6 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class _ChewieDemoState extends State<ChewieDemo> {
super.dispose();
}

List<String> srcs = [
"https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4"
];

Future<void> initializePlayer() async {
_videoPlayerController1 = VideoPlayerController.network(
'https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4',
);
_videoPlayerController2 = VideoPlayerController.network(
'https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4',
);
_videoPlayerController1 =
VideoPlayerController.network(srcs[currPlayIndex]);
_videoPlayerController2 =
VideoPlayerController.network(srcs[currPlayIndex]);
await Future.wait([
_videoPlayerController1.initialize(),
_videoPlayerController2.initialize()
Expand Down Expand Up @@ -108,6 +111,15 @@ class _ChewieDemoState extends State<ChewieDemo> {
autoPlay: true,
looping: true,

additionalOptions: (context) {
return <OptionItem>[
OptionItem(
onTap: toggleVideo,
iconData: Icons.live_tv_sharp,
title: 'Toggle Video Src',
),
];
},
subtitle: Subtitles(subtitles),
subtitleBuilder: (context, dynamic subtitle) => Container(
padding: const EdgeInsets.all(10.0),
Expand Down Expand Up @@ -137,6 +149,14 @@ class _ChewieDemoState extends State<ChewieDemo> {
);
}

int currPlayIndex = 0;

Future<void> toggleVideo() async {
await _videoPlayerController1.pause();
currPlayIndex = currPlayIndex == 0 ? 1 : 0;
await initializePlayer();
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
88 changes: 38 additions & 50 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Chewie extends StatefulWidget {
}

class ChewieState extends State<Chewie> {
bool _isFullScreen = false;
bool _isFullScreen = false;

bool get isControllerFullScreen => widget.controller.isFullScreen;
late PlayerNotifier notifier;

@override
Expand All @@ -62,11 +64,14 @@ class ChewieState extends State<Chewie> {
widget.controller.addListener(listener);
}
super.didUpdateWidget(oldWidget);
if (_isFullScreen != isControllerFullScreen) {
widget.controller._isFullScreen = _isFullScreen;
}
}

Future<void> listener() async {
if (widget.controller.isFullScreen && !_isFullScreen) {
_isFullScreen = true;
if (isControllerFullScreen && !_isFullScreen) {
_isFullScreen = isControllerFullScreen;
await _pushFullScreenWidget(context);
} else if (_isFullScreen) {
Navigator.of(
Expand Down Expand Up @@ -179,25 +184,24 @@ class ChewieState extends State<Chewie> {

void onEnterFullScreen() {
final videoWidth = widget.controller.videoPlayerController.value.size.width;
final videoHeight =
widget.controller.videoPlayerController.value.size.height;
final videoHeight = widget.controller.videoPlayerController.value.size.height;

if (widget.controller.systemOverlaysOnEnterFullScreen != null) {
/// Optional user preferred settings
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: widget.controller.systemOverlaysOnEnterFullScreen,
);
} else {
/// Default behavior
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);

// if (widget.controller.systemOverlaysOnEnterFullScreen != null) {
// /// Optional user preferred settings
// SystemChrome.setEnabledSystemUIMode(
// SystemUiMode.manual,
// overlays: widget.controller.systemOverlaysOnEnterFullScreen,
// );
// } else {
// /// Default behavior
// SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: SystemUiOverlay.values);
// }

if (widget.controller.deviceOrientationsOnEnterFullScreen != null) {
/// Optional user preferred settings
SystemChrome.setPreferredOrientations(
widget.controller.deviceOrientationsOnEnterFullScreen!,
);
SystemChrome.setPreferredOrientations(widget.controller.deviceOrientationsOnEnterFullScreen!);
} else {
final isLandscapeVideo = videoWidth > videoHeight;
final isPortraitVideo = videoWidth < videoHeight;
Expand Down Expand Up @@ -312,7 +316,8 @@ class ChewieController extends ChangeNotifier {
List<DeviceOrientation>? deviceOrientationsOnEnterFullScreen,
List<SystemUiOverlay>? systemOverlaysAfterFullScreen,
List<DeviceOrientation>? deviceOrientationsAfterFullScreen,
Widget Function(

Widget Function(
BuildContext,
Animation<double>,
Animation<double>,
Expand All @@ -321,23 +326,19 @@ class ChewieController extends ChangeNotifier {
routePageBuilder,
}) {
return ChewieController(
videoPlayerController:
videoPlayerController ?? this.videoPlayerController,
videoPlayerController: videoPlayerController ?? this.videoPlayerController,
optionsTranslation: optionsTranslation ?? this.optionsTranslation,
aspectRatio: aspectRatio ?? this.aspectRatio,
autoInitialize: autoInitialize ?? this.autoInitialize,
autoPlay: autoPlay ?? this.autoPlay,
startAt: startAt ?? this.startAt,
looping: looping ?? this.looping,
fullScreenByDefault: fullScreenByDefault ?? this.fullScreenByDefault,
cupertinoProgressColors:
cupertinoProgressColors ?? this.cupertinoProgressColors,
materialProgressColors:
materialProgressColors ?? this.materialProgressColors,
cupertinoProgressColors: cupertinoProgressColors ?? this.cupertinoProgressColors,
materialProgressColors: materialProgressColors ?? this.materialProgressColors,
placeholder: placeholder ?? this.placeholder,
overlay: overlay ?? this.overlay,
showControlsOnInitialize:
showControlsOnInitialize ?? this.showControlsOnInitialize,
showControlsOnInitialize: showControlsOnInitialize ?? this.showControlsOnInitialize,
showOptions: showOptions ?? this.showOptions,
optionsBuilder: optionsBuilder ?? this.optionsBuilder,
additionalOptions: additionalOptions ?? this.additionalOptions,
Expand All @@ -354,15 +355,10 @@ class ChewieController extends ChangeNotifier {
allowPlaybackSpeedChanging ?? this.allowPlaybackSpeedChanging,
useRootNavigator: useRootNavigator ?? this.useRootNavigator,
playbackSpeeds: playbackSpeeds ?? this.playbackSpeeds,
systemOverlaysOnEnterFullScreen: systemOverlaysOnEnterFullScreen ??
this.systemOverlaysOnEnterFullScreen,
deviceOrientationsOnEnterFullScreen:
deviceOrientationsOnEnterFullScreen ??
this.deviceOrientationsOnEnterFullScreen,
systemOverlaysAfterFullScreen:
systemOverlaysAfterFullScreen ?? this.systemOverlaysAfterFullScreen,
deviceOrientationsAfterFullScreen: deviceOrientationsAfterFullScreen ??
this.deviceOrientationsAfterFullScreen,
systemOverlaysOnEnterFullScreen: systemOverlaysOnEnterFullScreen ?? this.systemOverlaysOnEnterFullScreen,
deviceOrientationsOnEnterFullScreen: deviceOrientationsOnEnterFullScreen ?? this.deviceOrientationsOnEnterFullScreen,
systemOverlaysAfterFullScreen: systemOverlaysAfterFullScreen ?? this.systemOverlaysAfterFullScreen,
deviceOrientationsAfterFullScreen: deviceOrientationsAfterFullScreen ?? this.deviceOrientationsAfterFullScreen,
routePageBuilder: routePageBuilder ?? this.routePageBuilder,
);
}
Expand All @@ -385,17 +381,13 @@ class ChewieController extends ChangeNotifier {
/// the builder method. Just add your own options to the Widget
/// you'll build. If you want to hide the chewieOptions, just leave them
/// out from your Widget.
final Future<void> Function(
BuildContext context,
List<OptionItem> chewieOptions,
)? optionsBuilder;
final Future<void> Function(BuildContext context, List<OptionItem> chewieOptions)? optionsBuilder;

/// Add your own additional options on top of chewie options
final List<OptionItem> Function(BuildContext context)? additionalOptions;

/// Define here your own Widget on how your n'th subtitle will look like
final Widget Function(BuildContext context, dynamic subtitle)?
subtitleBuilder;
final Widget Function(BuildContext context, dynamic subtitle)? subtitleBuilder;

/// Add a List of Subtitles here in `Subtitles.subtitle`
Subtitles? subtitle;
Expand Down Expand Up @@ -427,8 +419,7 @@ class ChewieController extends ChangeNotifier {

/// When the video playback runs into an error, you can build a custom
/// error message.
final Widget Function(BuildContext context, String errorMessage)?
errorBuilder;
final Widget Function(BuildContext context, String errorMessage)? errorBuilder;

/// The Aspect Ratio of the Video. Important to get the correct size of the
/// video!
Expand Down Expand Up @@ -491,8 +482,7 @@ class ChewieController extends ChangeNotifier {
final ChewieRoutePageBuilder? routePageBuilder;

static ChewieController of(BuildContext context) {
final chewieControllerProvider = context
.dependOnInheritedWidgetOfExactType<_ChewieControllerProvider>()!;
final chewieControllerProvider = context.dependOnInheritedWidgetOfExactType<_ChewieControllerProvider>()!;

return chewieControllerProvider.controller;
}
Expand All @@ -506,8 +496,7 @@ class ChewieController extends ChangeNotifier {
Future _initialize() async {
await videoPlayerController.setLooping(looping);

if ((autoInitialize || autoPlay) &&
!videoPlayerController.value.isInitialized) {
if ((autoInitialize || autoPlay) && !videoPlayerController.value.isInitialized) {
await videoPlayerController.initialize();
}

Expand Down Expand Up @@ -590,6 +579,5 @@ class _ChewieControllerProvider extends InheritedWidget {
final ChewieController controller;

@override
bool updateShouldNotify(_ChewieControllerProvider old) =>
controller != old.controller;
bool updateShouldNotify(_ChewieControllerProvider old) => controller != old.controller;
}
7 changes: 6 additions & 1 deletion lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class CupertinoControls extends StatefulWidget {
const CupertinoControls({
required this.backgroundColor,
required this.iconColor,
this.showPlayButton = true,
Key? key,
}) : super(key: key);

final Color backgroundColor;
final Color iconColor;
final bool showPlayButton;

@override
State<StatefulWidget> createState() {
Expand All @@ -45,6 +47,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
bool _subtitleOn = false;

late VideoPlayerController controller;

// We know that _chewieController is set in didChangeDependencies
ChewieController get chewieController => _chewieController!;
ChewieController? _chewieController;
Expand Down Expand Up @@ -288,6 +291,8 @@ class _CupertinoControlsState extends State<CupertinoControls>

Widget _buildHitArea() {
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool showPlayButton =
widget.showPlayButton && !_latestValue.isPlaying && !_dragging;

return GestureDetector(
onTap: _latestValue.isPlaying
Expand All @@ -304,7 +309,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
iconColor: widget.iconColor,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: !_latestValue.isPlaying && !_dragging,
show: showPlayButton,
onPressed: _playPause,
),
);
Expand Down
Loading

0 comments on commit 67bf9fc

Please sign in to comment.