Skip to content

Commit

Permalink
Feature/november changes 3 (#154)
Browse files Browse the repository at this point in the history
* Added initialized event

* Added INITIALIZED event

* Added autoDetectFullscreenDeviceOrientation implementation

* Fixed autoPlay background issue

* Fixed cupertino icons

* Fixed progress bar not working correctly for iOS 12 with file datasource

* Fixed progress bar not working correctly for iOS 12 with file datasource

* 0.0.36 release
  • Loading branch information
jhomlala authored Nov 29, 2020
1 parent b95cb80 commit 637757a
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 36 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
## 0.0.36
* Added INITIALIZED event
* Added autoDetectFullscreenDeviceOrientation in BetterPlayerConfiguration
* Fixed autoPlay background issue
* Removed open_iconic_flutter icons used in Cupertino controls
* Added cupertino_icons for icons used Cupertiono controls
* Fixed progress bar not working correctly for iOS 12 with file datasource
* Removed yellow line below progress text (fixed by https://github.com/mtAlves)

## 0.0.35
* Fixed iOS black screen issue
* Fixed full screen placeholder issue
* Fixed event not firing in enterFullScreen and exitFullScreen
* Fixed subtitles parsing issues


## 0.0.34
* Added memory data source
* Added factories: network, file, memory for BetterPlayerDataSource
Expand Down
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.35
better_player: ^0.0.36
```
2. Install it
Expand Down Expand Up @@ -315,6 +315,14 @@ Possible configuration options:
///Defines translations used in player. If null, then default english translations
///will be used.
final List<BetterPlayerTranslations> translations;
///Defines if player should auto detect full screen device orientation based
///on aspect ratio of the video. If aspect ratio of the video is < 1 then
///video will played in full screen in portrait mode. If aspect ratio is >= 1
///then video will be played horizontally. If this parameter is true, then
///[deviceOrientationsOnFullScreen] and [fullScreenAspectRatio] value will be
/// ignored.
final bool autoDetectFullscreenDeviceOrientation;
```

### BetterPlayerSubtitlesConfiguration
Expand Down Expand Up @@ -653,7 +661,8 @@ https://flutter.dev/docs/development/accessibility-and-localization/internationa
### Listen to video events
You can listen to video player events like:
```dart
PLAY,
INITIALIZED,
PLAY,
PAUSE,
SEEK_TO,
OPEN_FULLSCREEN,
Expand Down
2 changes: 2 additions & 0 deletions example/lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ class Constants {
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4";
static const String forBiggerJoyridesVideoUrl =
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4";
static const String verticalVideoUrl =
"http://www.exit109.com/~dnn/clips/RW20seconds_1.mp4";
}
72 changes: 72 additions & 0 deletions example/lib/pages/auto_fullscreen_orientation_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import 'package:better_player/better_player.dart';
import 'package:better_player_example/constants.dart';
import 'package:flutter/material.dart';

class AutoFullscreenOrientationPage extends StatefulWidget {
@override
_AutoFullscreenOrientationPageState createState() =>
_AutoFullscreenOrientationPageState();
}

class _AutoFullscreenOrientationPageState
extends State<AutoFullscreenOrientationPage> {
BetterPlayerController _betterPlayerController;

@override
void initState() {
BetterPlayerConfiguration betterPlayerConfiguration =
BetterPlayerConfiguration(
aspectRatio: 16 / 9,
fit: BoxFit.contain,
autoDetectFullscreenDeviceOrientation: true);
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.NETWORK, Constants.forBiggerBlazesUrl);
_betterPlayerController = BetterPlayerController(betterPlayerConfiguration);
_betterPlayerController.setupDataSource(dataSource);
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Normal player"),
),
body: Column(
children: [
const SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
"Aspect ratio and device orientation on full screen will be "
"managed by the BetterPlayer. Click on the fullscreen option.",
style: TextStyle(fontSize: 16),
),
),
AspectRatio(
aspectRatio: 16 / 9,
child: BetterPlayer(controller: _betterPlayerController),
),
RaisedButton(
child: Text("Play horizontal video"),
onPressed: () {
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.NETWORK,
Constants.forBiggerBlazesUrl);
_betterPlayerController.setupDataSource(dataSource);
},
),
RaisedButton(
child: Text("Play vertical video"),
onPressed: () async {
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.NETWORK,
Constants.verticalVideoUrl);
_betterPlayerController.setupDataSource(dataSource);
},
),
],
),
);
}
}
6 changes: 5 additions & 1 deletion example/lib/pages/basic_player_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class _BasicPlayerPageState extends State<BasicPlayerPage> {
FutureBuilder<String>(
future: Utils.getFileUrl(Constants.fileTestVideoUrl),
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
return BetterPlayer.file(snapshot.data);
if (snapshot.data != null) {
return BetterPlayer.file(snapshot.data);
} else {
return const SizedBox();
}
},
)
],
Expand Down
4 changes: 4 additions & 0 deletions example/lib/pages/welcome_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:better_player_example/pages/auto_fullscreen_orientation_page.dart';
import 'package:better_player_example/pages/basic_player_page.dart';
import 'package:better_player_example/pages/cache_page.dart';
import 'package:better_player_example/pages/controller_controls_page.dart';
Expand Down Expand Up @@ -103,6 +104,9 @@ class _WelcomePageState extends State<WelcomePage> {
_buildExampleElementWidget("Controller controls page", () {
_navigateToPage(ControllerControlsPage());
}),
_buildExampleElementWidget("Auto fullscreen orientation page", () {
_navigateToPage(AutoFullscreenOrientationPage());
}),
];
}

Expand Down
5 changes: 3 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ environment:
sdk: ">=2.2.2 <3.0.0"

dependencies:
better_player:
path: ../
better_player: any
#better_player:
# path: ../
flutter:
sdk: flutter
flutter_localizations:
Expand Down
9 changes: 8 additions & 1 deletion ios/Classes/FLTBetterPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,14 @@ - (int64_t)position {
}

- (int64_t)duration {
return FLTCMTimeToMillis([[_player currentItem] duration]);
CMTime time;
if (@available(iOS 13, *)) {
time = [[_player currentItem] duration];
} else {
time = [[[_player currentItem] asset] duration];
}

return FLTCMTimeToMillis(time);
}

- (void)seekTo:(int)location {
Expand Down
13 changes: 13 additions & 0 deletions lib/src/configuration/better_player_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ class BetterPlayerConfiguration {
///will be used.
final List<BetterPlayerTranslations> translations;

///Defines if player should auto detect full screen device orientation based
///on aspect ratio of the video. If aspect ratio of the video is < 1 then
///video will played in full screen in portrait mode. If aspect ratio is >= 1
///then video will be played horizontally. If this parameter is true, then
///[deviceOrientationsOnFullScreen] and [fullScreenAspectRatio] value will be
/// ignored.
final bool autoDetectFullscreenDeviceOrientation;

const BetterPlayerConfiguration({
this.aspectRatio,
this.autoPlay = false,
Expand Down Expand Up @@ -113,6 +121,7 @@ class BetterPlayerConfiguration {
this.rotation = 0,
this.playerVisibilityChangedBehavior,
this.translations,
this.autoDetectFullscreenDeviceOrientation = false,
});

BetterPlayerConfiguration copyWith({
Expand All @@ -138,6 +147,7 @@ class BetterPlayerConfiguration {
double rotation,
Function(double visibilityFraction) playerVisibilityChangedBehavior,
BetterPlayerTranslations translations,
bool autoDetectFullscreenDeviceOrientation,
}) {
return BetterPlayerConfiguration(
aspectRatio: aspectRatio ?? this.aspectRatio,
Expand Down Expand Up @@ -166,6 +176,9 @@ class BetterPlayerConfiguration {
playerVisibilityChangedBehavior: playerVisibilityChangedBehavior ??
this.playerVisibilityChangedBehavior,
translations: translations ?? this.translations,
autoDetectFullscreenDeviceOrientation:
autoDetectFullscreenDeviceOrientation ??
this.autoDetectFullscreenDeviceOrientation,
);
}
}
1 change: 1 addition & 0 deletions lib/src/configuration/better_player_event_type.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///Supported event types
enum BetterPlayerEventType {
INITIALIZED,
PLAY,
PAUSE,
SEEK_TO,
Expand Down
10 changes: 5 additions & 5 deletions lib/src/controls/better_player_controls_configuration.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:ui';

import 'package:better_player/src/controls/better_player_overflow_menu_item.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:open_iconic_flutter/open_iconic_flutter.dart';

class BetterPlayerControlsConfiguration {
///Color of the control bars
Expand Down Expand Up @@ -173,10 +173,10 @@ class BetterPlayerControlsConfiguration {

factory BetterPlayerControlsConfiguration.cupertino() {
return BetterPlayerControlsConfiguration(
fullscreenEnableIcon: OpenIconicIcons.fullscreenEnter,
fullscreenDisableIcon: OpenIconicIcons.fullscreenExit,
playIcon: OpenIconicIcons.mediaPlay,
pauseIcon: OpenIconicIcons.mediaPause,
fullscreenEnableIcon: CupertinoIcons.fullscreen,
fullscreenDisableIcon: CupertinoIcons.fullscreen_exit,
playIcon: CupertinoIcons.play_arrow_solid,
pauseIcon: CupertinoIcons.pause_solid,
enableProgressText: true);
}
}
47 changes: 38 additions & 9 deletions lib/src/core/better_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ class BetterPlayer extends StatefulWidget {
}
}

class BetterPlayerState extends State<BetterPlayer> {
BetterPlayerDataSource get betterPlayerDataSource =>
widget.controller.betterPlayerDataSource;
class BetterPlayerState extends State<BetterPlayer>
with WidgetsBindingObserver {
BetterPlayerConfiguration get _betterPlayerConfiguration =>
widget.controller.betterPlayerConfiguration;

bool _isFullScreen = false;

@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
Future.delayed(Duration.zero, () {
_setup();
});
Expand All @@ -82,6 +84,7 @@ class BetterPlayerState extends State<BetterPlayer> {

@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
widget.controller.removeListener(onFullScreenChanged);

///Controller from list widget must be dismissed manually
Expand Down Expand Up @@ -158,8 +161,7 @@ class BetterPlayerState extends State<BetterPlayer> {
var controllerProvider = BetterPlayerControllerProvider(
controller: widget.controller, child: _buildPlayer());

var routePageBuilder =
widget.controller.betterPlayerConfiguration.routePageBuilder;
var routePageBuilder = _betterPlayerConfiguration.routePageBuilder;
if (routePageBuilder == null) {
return _defaultRoutePageBuilder(
context, animation, secondaryAnimation, controllerProvider);
Expand All @@ -178,11 +180,32 @@ class BetterPlayerState extends State<BetterPlayer> {
);

SystemChrome.setEnabledSystemUIOverlays([]);

if (isAndroid) {
SystemChrome.setPreferredOrientations(
widget.controller.betterPlayerConfiguration
.deviceOrientationsOnFullScreen,
);
if (_betterPlayerConfiguration.autoDetectFullscreenDeviceOrientation ==
true) {
var aspectRatio =
widget?.controller?.videoPlayerController?.value?.aspectRatio ??
1.0;
List<DeviceOrientation> deviceOrientations;
if (aspectRatio < 1.0) {
deviceOrientations = [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown
];
} else {
deviceOrientations = [
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight
];
}
SystemChrome.setPreferredOrientations(deviceOrientations);
} else {
SystemChrome.setPreferredOrientations(
widget.controller.betterPlayerConfiguration
.deviceOrientationsOnFullScreen,
);
}
}

if (!widget.controller.allowedScreenSleep) {
Expand Down Expand Up @@ -213,4 +236,10 @@ class BetterPlayerState extends State<BetterPlayer> {
),
);
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
widget.controller.setAppLifecycleState(state);
}
}
Loading

0 comments on commit 637757a

Please sign in to comment.