diff --git a/CHANGELOG.md b/CHANGELOG.md index e030096b2..818e0af77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index fdfe654e6..604bb905e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java b/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java index 9d7b8187a..9fd3fc501 100644 --- a/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java +++ b/android/src/main/java/com/jhomlala/better_player/BetterPlayer.java @@ -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) { diff --git a/example/lib/pages/normal_player_page.dart b/example/lib/pages/normal_player_page.dart index 71dab3835..0d48d10fb 100644 --- a/example/lib/pages/normal_player_page.dart +++ b/example/lib/pages/normal_player_page.dart @@ -22,7 +22,18 @@ class _NormalPlayerPageState extends State { 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 diff --git a/example/lib/pages/overridden_aspect_ratio_page.dart b/example/lib/pages/overridden_aspect_ratio_page.dart new file mode 100644 index 000000000..d1d128f67 --- /dev/null +++ b/example/lib/pages/overridden_aspect_ratio_page.dart @@ -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 { + 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), + ), + ], + ), + ); + } +} diff --git a/example/lib/pages/video_list/video_list_widget.dart b/example/lib/pages/video_list/video_list_widget.dart index bb5f0171d..bf8d58cec 100644 --- a/example/lib/pages/video_list/video_list_widget.dart +++ b/example/lib/pages/video_list/video_list_widget.dart @@ -66,28 +66,30 @@ class _VideoListWidgetState extends State { "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); + }, + ), + ]), + ), ], ), ); diff --git a/example/lib/pages/welcome_page.dart b/example/lib/pages/welcome_page.dart index 435ca598a..45e3cfea7 100644 --- a/example/lib/pages/welcome_page.dart +++ b/example/lib/pages/welcome_page.dart @@ -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'; @@ -107,6 +108,9 @@ class _WelcomePageState extends State { _buildExampleElementWidget("Auto fullscreen orientation page", () { _navigateToPage(AutoFullscreenOrientationPage()); }), + _buildExampleElementWidget("Overridden aspect ratio page", () { + _navigateToPage(OverriddenAspectRatioPage()); + }), ]; } diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 0a22c4251..822458df8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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: diff --git a/lib/src/controls/better_player_material_controls.dart b/lib/src/controls/better_player_material_controls.dart index e9817e889..14817317e 100644 --- a/lib/src/controls/better_player_material_controls.dart +++ b/lib/src/controls/better_player_material_controls.dart @@ -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( diff --git a/lib/src/core/better_player.dart b/lib/src/core/better_player.dart index 7f14a8eb9..c65ca4020 100644 --- a/lib/src/core/better_player.dart +++ b/lib/src/core/better_player.dart @@ -179,7 +179,7 @@ class BetterPlayerState extends State opaque: true, ); - SystemChrome.setEnabledSystemUIOverlays([]); + await SystemChrome.setEnabledSystemUIOverlays([]); if (isAndroid) { if (_betterPlayerConfiguration.autoDetectFullscreenDeviceOrientation == @@ -199,13 +199,18 @@ class BetterPlayerState extends State 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) { @@ -220,9 +225,9 @@ class BetterPlayerState extends State // 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); } diff --git a/lib/src/core/better_player_controller.dart b/lib/src/core/better_player_controller.dart index 7df841ab5..5cda6a019 100644 --- a/lib/src/core/better_player_controller.dart +++ b/lib/src/core/better_player_controller.dart @@ -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; @@ -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, @@ -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) { @@ -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) { diff --git a/lib/src/core/better_player_with_controls.dart b/lib/src/core/better_player_with_controls.dart index 80aa36a8a..76653e576 100644 --- a/lib/src/core/better_player_with_controls.dart +++ b/lib/src/core/better_player_with_controls.dart @@ -83,9 +83,11 @@ class _BetterPlayerWithControlsState extends State { BetterPlayerUtils.calculateAspectRatio(context); } } else { - aspectRatio = - betterPlayerController.betterPlayerConfiguration.aspectRatio ?? - BetterPlayerUtils.calculateAspectRatio(context); + aspectRatio = betterPlayerController.getAspectRatio(); + } + + if (aspectRatio == null) { + aspectRatio = 16 / 9; } return Center( diff --git a/lib/src/list/better_player_list_video_player.dart b/lib/src/list/better_player_list_video_player.dart index da764ee24..ec96fed1c 100644 --- a/lib/src/list/better_player_list_video_player.dart +++ b/lib/src/list/better_player_list_video_player.dart @@ -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, diff --git a/lib/src/playlist/better_player_playlist.dart b/lib/src/playlist/better_player_playlist.dart index 6a8f2c904..dc9a79a76 100644 --- a/lib/src/playlist/better_player_playlist.dart +++ b/lib/src/playlist/better_player_playlist.dart @@ -121,7 +121,7 @@ class _BetterPlayerPlaylistState extends State { @override Widget build(BuildContext context) { return AspectRatio( - aspectRatio: widget.betterPlayerConfiguration.aspectRatio ?? + aspectRatio: _controller.getAspectRatio() ?? BetterPlayerUtils.calculateAspectRatio(context), child: BetterPlayer( key: Key(_getKey()), diff --git a/pubspec.yaml b/pubspec.yaml index 398e8bf36..dbf010773 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 homepage: https://github.com/jhomlala/betterplayer