Skip to content

Commit

Permalink
Added possibility to show fullscreen in portrait mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jhomlala committed Oct 17, 2020
1 parent 31a284e commit 31b4688
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ Possible configuration options:
/// Defines if the player will sleep in fullscreen or not
final bool allowedScreenSleep;
/// Defines aspect ratio which will be used in fullscreen
final double fullScreenAspectRatio;
/// Defines the set of allowed device orientations on entering fullscreen
final List<DeviceOrientation> deviceOrientationsOnFullScreen;
/// Defines the system overlays visible after exiting fullscreen
final List<SystemUiOverlay> systemOverlaysAfterFullScreen;
Expand Down
6 changes: 6 additions & 0 deletions example/lib/other_page/other_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:better_player/better_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class OtherPage extends StatefulWidget {
@override
Expand Down Expand Up @@ -46,6 +47,11 @@ class _OtherPageState extends State<OtherPage> {
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
betterPlayerConfiguration: BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fullScreenAspectRatio: 9 / 16,
deviceOrientationsOnFullScreen: [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
],
),
),
),
Expand Down
15 changes: 15 additions & 0 deletions lib/src/configuration/better_player_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class BetterPlayerConfiguration {
/// Defines if the player will sleep in fullscreen or not
final bool allowedScreenSleep;

/// Defines aspect ratio which will be used in fullscreen
final double fullScreenAspectRatio;

/// Defines the set of allowed device orientations on entering fullscreen
final List<DeviceOrientation> deviceOrientationsOnFullScreen;

/// Defines the system overlays visible after exiting fullscreen
final List<SystemUiOverlay> systemOverlaysAfterFullScreen;

Expand Down Expand Up @@ -82,6 +88,11 @@ class BetterPlayerConfiguration {
this.showControlsOnInitialize = true,
this.errorBuilder,
this.allowedScreenSleep = true,
this.fullScreenAspectRatio,
this.deviceOrientationsOnFullScreen = const [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
],
this.systemOverlaysAfterFullScreen = SystemUiOverlay.values,
this.deviceOrientationsAfterFullScreen = const [
DeviceOrientation.portraitUp,
Expand Down Expand Up @@ -109,6 +120,8 @@ class BetterPlayerConfiguration {
bool showControlsOnInitialize,
Widget Function(BuildContext context, String errorMessage) errorBuilder,
bool allowedScreenSleep,
double fullScreenAspectRatio,
List<DeviceOrientation> deviceOrientationsOnFullScreen,
List<SystemUiOverlay> systemOverlaysAfterFullScreen,
List<DeviceOrientation> deviceOrientationsAfterFullScreen,
BetterPlayerRoutePageBuilder routePageBuilder,
Expand All @@ -131,6 +144,8 @@ class BetterPlayerConfiguration {
showControlsOnInitialize ?? this.showControlsOnInitialize,
errorBuilder: errorBuilder ?? this.errorBuilder,
allowedScreenSleep: allowedScreenSleep ?? this.allowedScreenSleep,
deviceOrientationsOnFullScreen: deviceOrientationsOnFullScreen ??
this.deviceOrientationsOnFullScreen,
systemOverlaysAfterFullScreen:
systemOverlaysAfterFullScreen ?? this.systemOverlaysAfterFullScreen,
deviceOrientationsAfterFullScreen: deviceOrientationsAfterFullScreen ??
Expand Down
8 changes: 4 additions & 4 deletions lib/src/core/better_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ class BetterPlayerState extends State<BetterPlayer> {

SystemChrome.setEnabledSystemUIOverlays([]);
if (isAndroid) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
SystemChrome.setPreferredOrientations(
widget.controller.betterPlayerConfiguration
.deviceOrientationsOnFullScreen,
);
}

if (!widget.controller.allowedScreenSleep) {
Expand Down
16 changes: 13 additions & 3 deletions lib/src/core/better_player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,23 @@ class _BetterPlayerWithControlsState extends State<BetterPlayerWithControls> {
final BetterPlayerController betterPlayerController =
BetterPlayerController.of(context);

var aspectRatio;
if (betterPlayerController.isFullScreen) {
aspectRatio = betterPlayerController
.betterPlayerConfiguration.fullScreenAspectRatio ??
BetterPlayerUtils.calculateAspectRatio(context);
} else {
aspectRatio =
betterPlayerController.betterPlayerConfiguration.aspectRatio ??
BetterPlayerUtils.calculateAspectRatio(context);
}

return Center(
child: Container(
width: double.infinity,
color: Colors.black,
child: AspectRatio(
aspectRatio: betterPlayerController.aspectRatio ??
BetterPlayerUtils.calculateAspectRatio(context),
aspectRatio: aspectRatio,
child: _buildPlayerWithControls(betterPlayerController, context),
),
),
Expand All @@ -80,7 +90,7 @@ class _BetterPlayerWithControlsState extends State<BetterPlayerWithControls> {
var configuration = betterPlayerController.betterPlayerConfiguration;
var rotation = configuration.rotation;

if (!(rotation <= 360 && rotation % 90 == 0)){
if (!(rotation <= 360 && rotation % 90 == 0)) {
print("Invalid rotation provided. Using rotation = 0");
rotation = 0;
}
Expand Down

0 comments on commit 31b4688

Please sign in to comment.