Skip to content

Commit

Permalink
Feature/february changes 11 (jhomlala#352)
Browse files Browse the repository at this point in the history
* Updated documentation

* Added null checking for videoPlayerController inside BetterPlayerController.

* Added setMixWithOthers

* Added initialStartIndex in BetterPlayerPlaylistConfiguration.

* Fixed issue where player did not disposed properly on app quit

* Added placeholder parameter in BetterPlayerDataSource

* Flutter format, version update

* Updated documentation

* Added BP images

* Added BP images

* Flutter format
  • Loading branch information
jhomlala authored Feb 28, 2021
1 parent 2831162 commit 83e68e9
Show file tree
Hide file tree
Showing 35 changed files with 196 additions and 105 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 0.0.60
* Updated documentation.
* Added null checking for videoPlayerController inside BetterPlayerController.
* Added setMixWithOthers method to BetterPlayerController.
* Added initialStartIndex in BetterPlayerPlaylistConfiguration.
* Fixed issue where player did not disposed properly on app quit.
* Added placeholder parameter in BetterPlayerDataSource.
* Fixed custom material full screen icons (by https://github.com/FelipeFernandesLeandro)

## 0.0.59
* Fixed WEBVTT subtitles parsing.
* Updated ExoPlayer version.
Expand All @@ -6,7 +15,7 @@
* Added fix for iOS aspect ratio issue.
* Fixed auto play issue where player starts video after load initialization process and player is not visible.
* Updated texts in examples.
* Added missing widevine DRM parameters (by https://github.com/FlutterSu)
* Added missing widevine DRM parameters (by https://github.com/FlutterSu).

## 0.0.58
* Added overflowModalColor and overflowModalTextColor in BetterPlayerControlsConfiguration.
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.59
better_player: ^0.0.60
```
2. Install it
Expand Down Expand Up @@ -567,6 +567,10 @@ Possible configuration options:
///Should videos be looped
final bool loopVideos;
///Index of video that will start on playlist start. Id must be less than
///elements in data source list. Default is 0.
final int initialStartIndex;
```

### BetterPlayerDataSource
Expand Down Expand Up @@ -644,6 +648,15 @@ Possible configuration options:
///Extension of video without dot. Used only in memory data source.
final String videoExtension;
///Configuration of content protection
final BetterPlayerDrmConfiguration drmConfiguration;
///Placeholder widget which will be shown until video load or play. This
///placeholder may be useful if you want to show placeholder before each video
///in playlist. Otherwise, you should use placeholder from
/// BetterPlayerConfiguration.
final Widget placeholder;
```


Expand Down Expand Up @@ -977,7 +990,12 @@ Widevine (license url based):
_widevineController.setupDataSource(_widevineDataSource);
```

### Set mix audio with others
You can enable mix with audio with others app with method:
```dart
betterPlayerController.setMixWithOthers(true)
```
Default value is false.

### More documentation
https://pub.dev/documentation/better_player/latest/better_player/better_player-library.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public void onCancel(Object o) {

surface = new Surface(textureEntry.surfaceTexture());
exoPlayer.setVideoSurface(surface);
setAudioAttributes(exoPlayer);
setAudioAttributes(exoPlayer, true);

exoPlayer.addListener(
new EventListener() {
Expand Down Expand Up @@ -557,18 +557,18 @@ void sendBufferingUpdate() {
eventSink.success(event);
}

private static void setAudioAttributes(SimpleExoPlayer exoPlayer) {
private void setAudioAttributes(SimpleExoPlayer exoPlayer, Boolean mixWithOthers) {
Player.AudioComponent audioComponent = exoPlayer.getAudioComponent();
if (audioComponent == null) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

audioComponent.setAudioAttributes(
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), false);
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), !mixWithOthers);
} else {
audioComponent.setAudioAttributes(
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build(), false);
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build(), !mixWithOthers);
}
}

Expand Down Expand Up @@ -788,6 +788,10 @@ private void sendSeekToEvent(long positionMs) {
eventSink.success(event);
}

public void setMixWithOthers(Boolean mixWithOthers) {
setAudioAttributes(exoPlayer,mixWithOthers);
}


void dispose() {
disposeMediaSession();
Expand Down Expand Up @@ -823,7 +827,6 @@ public int hashCode() {
result = 31 * result + (surface != null ? surface.hashCode() : 0);
return result;
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class BetterPlayerPlugin implements FlutterPlugin, ActivityAware, MethodC
private static final String INDEX_PARAMETER = "index";
private static final String LICENSE_URL_PARAMETER = "licenseUrl";
private static final String DRM_HEADERS_PARAMETER = "drmHeaders";
private static final String MIX_WITH_OTHERS_PARAMETER = "mixWithOthers";

private static final String INIT_METHOD = "init";
private static final String CREATE_METHOD = "create";
Expand All @@ -83,6 +84,7 @@ public class BetterPlayerPlugin implements FlutterPlugin, ActivityAware, MethodC
private static final String ENABLE_PICTURE_IN_PICTURE_METHOD = "enablePictureInPicture";
private static final String DISABLE_PICTURE_IN_PICTURE_METHOD = "disablePictureInPicture";
private static final String IS_PICTURE_IN_PICTURE_SUPPORTED_METHOD = "isPictureInPictureSupported";
private static final String SET_MIX_WITH_OTHERS_METHOD = "setMixWithOthers";
private static final String DISPOSE_METHOD = "dispose";

private final LongSparseArray<BetterPlayer> videoPlayers = new LongSparseArray<>();
Expand Down Expand Up @@ -141,6 +143,7 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
if (flutterState == null) {
Log.wtf(TAG, "Detached from the engine before registering to it.");
}
disposeAllPlayers();
BetterPlayerCache.releaseCache();
flutterState.stopListening();
flutterState = null;
Expand Down Expand Up @@ -270,7 +273,9 @@ private void onMethodCall(MethodCall call, Result result, long textureId, Better
player.setAudioTrack(call.argument(NAME_PARAMETER), call.argument(INDEX_PARAMETER));
result.success(null);
break;

case SET_MIX_WITH_OTHERS_METHOD:
player.setMixWithOthers(call.argument(MIX_WITH_OTHERS_PARAMETER));
break;
case DISPOSE_METHOD:
dispose(player, textureId);
result.success(null);
Expand Down
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_localizations/flutter_localizations.dart';
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
29 changes: 19 additions & 10 deletions example/lib/pages/playlist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class _PlaylistPageState extends State<PlaylistPage> {

_PlaylistPageState() {
_betterPlayerConfiguration = BetterPlayerConfiguration(
autoPlay: true,
aspectRatio: 1,
fit: BoxFit.cover,
placeholderOnTop: true,
showPlaceholderUntilPlay: true,
subtitlesConfiguration: BetterPlayerSubtitlesConfiguration(fontSize: 10),
deviceOrientationsAfterFullScreen: [
DeviceOrientation.portraitUp,
Expand All @@ -29,25 +30,33 @@ class _PlaylistPageState extends State<PlaylistPage> {
);
_betterPlayerPlaylistConfiguration = BetterPlayerPlaylistConfiguration(
loopVideos: true,
nextVideoDelay: Duration(seconds: 5),
nextVideoDelay: Duration(seconds: 1),
);
}

Future<List<BetterPlayerDataSource>> setupData() async {
_dataSourceList.add(
BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
Constants.forBiggerBlazesUrl,
subtitles: BetterPlayerSubtitlesSource.single(
type: BetterPlayerSubtitlesSourceType.file,
url: await Utils.getFileUrl(Constants.fileExampleSubtitlesUrl),
),
),
BetterPlayerDataSourceType.network, Constants.forBiggerBlazesUrl,
subtitles: BetterPlayerSubtitlesSource.single(
type: BetterPlayerSubtitlesSourceType.file,
url: await Utils.getFileUrl(Constants.fileExampleSubtitlesUrl),
),
placeholder: Image.network(
Constants.catImageUrl,
fit: BoxFit.cover,
)),
);

_dataSourceList.add(
BetterPlayerDataSource(
BetterPlayerDataSourceType.network, Constants.bugBuckBunnyVideoUrl),
BetterPlayerDataSourceType.network,
Constants.bugBuckBunnyVideoUrl,
placeholder: Image.network(
Constants.catImageUrl,
fit: BoxFit.cover,
),
),
);
_dataSourceList.add(
BetterPlayerDataSource(
Expand Down
30 changes: 0 additions & 30 deletions example/test/widget_test.dart

This file was deleted.

17 changes: 14 additions & 3 deletions ios/Classes/FLTBetterPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,6 @@ - (void)setRestoreUserInterfaceForPIPStopCompletionHandler:(BOOL)restore

- (void)setupPipController {
if (@available(iOS 9.0, *)) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
if (!_pipController && self._playerLayer && [AVPictureInPictureController isPictureInPictureSupported]) {
Expand Down Expand Up @@ -745,6 +744,17 @@ - (void) setAudioTrack:(NSString*) name index:(int) index{
}

}

}

- (void)setMixWithOthers:(bool)mixWithOthers {
if (mixWithOthers) {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];
} else {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
}
}


Expand Down Expand Up @@ -900,6 +910,7 @@ - (void)onPlayerSetup:(FLTBetterPlayer*)player
eventChannelWithName:[NSString stringWithFormat:@"better_player_channel/videoEvents%lld",
textureId]
binaryMessenger:_messenger];
[player setMixWithOthers:false];
[eventChannel setStreamHandler:player];
player.eventChannel = eventChannel;
_players[@(textureId)] = player;
Expand Down Expand Up @@ -927,7 +938,6 @@ - (void) setupRemoteNotification :(FLTBetterPlayer*) player{
}

- (void) setRemoteCommandsNotificationActive{
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:true error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
}
Expand Down Expand Up @@ -1087,7 +1097,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {

if ([@"init" isEqualToString:call.method]) {
// Allow audio playback when the Ring/Silent switch is set to silent
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
for (NSNumber* textureId in _players) {
[_registry unregisterTexture:[textureId unsignedIntegerValue]];
[_players[textureId] dispose];
Expand Down Expand Up @@ -1217,6 +1226,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
NSString* name = argsMap[@"name"];
int index = [argsMap[@"index"] intValue];
[player setAudioTrack:name index: index];
} else if ([@"setMixWithOthers" isEqualToString:call.method]){
[player setMixWithOthers:[argsMap[@"mixWithOthers"] boolValue]];
}

else {
Expand Down
8 changes: 4 additions & 4 deletions lib/src/configuration/better_player_cache_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ class BetterPlayerCacheConfiguration {
///Enable cache for network data source
final bool useCache;

/// The maximum cache size to keep on disk in bytes.
/// Android only option. This value is used only when first video access
/// cache. This value is used for all players within your app. It can't be
/// changed during app work.
/// The maximum cache size to keep on disk in bytes. This value is used only
/// when first video access. cache. This value is used for all players within
/// your app. It can't be changed during app work.
// Android only option.
final int maxCacheSize;

/// The maximum size of each individual file in bytes.
Expand Down
Loading

0 comments on commit 83e68e9

Please sign in to comment.