Skip to content

Commit 83e68e9

Browse files
authored
Feature/february changes 11 (jhomlala#352)
* 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
1 parent 2831162 commit 83e68e9

35 files changed

+196
-105
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 0.0.60
2+
* Updated documentation.
3+
* Added null checking for videoPlayerController inside BetterPlayerController.
4+
* Added setMixWithOthers method to BetterPlayerController.
5+
* Added initialStartIndex in BetterPlayerPlaylistConfiguration.
6+
* Fixed issue where player did not disposed properly on app quit.
7+
* Added placeholder parameter in BetterPlayerDataSource.
8+
* Fixed custom material full screen icons (by https://github.com/FelipeFernandesLeandro)
9+
110
## 0.0.59
211
* Fixed WEBVTT subtitles parsing.
312
* Updated ExoPlayer version.
@@ -6,7 +15,7 @@
615
* Added fix for iOS aspect ratio issue.
716
* Fixed auto play issue where player starts video after load initialization process and player is not visible.
817
* Updated texts in examples.
9-
* Added missing widevine DRM parameters (by https://github.com/FlutterSu)
18+
* Added missing widevine DRM parameters (by https://github.com/FlutterSu).
1019

1120
## 0.0.58
1221
* Added overflowModalColor and overflowModalTextColor in BetterPlayerControlsConfiguration.

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is
3737

3838
```yaml
3939
dependencies:
40-
better_player: ^0.0.59
40+
better_player: ^0.0.60
4141
```
4242
4343
2. Install it
@@ -567,6 +567,10 @@ Possible configuration options:
567567
568568
///Should videos be looped
569569
final bool loopVideos;
570+
571+
///Index of video that will start on playlist start. Id must be less than
572+
///elements in data source list. Default is 0.
573+
final int initialStartIndex;
570574
```
571575

572576
### BetterPlayerDataSource
@@ -644,6 +648,15 @@ Possible configuration options:
644648
645649
///Extension of video without dot. Used only in memory data source.
646650
final String videoExtension;
651+
652+
///Configuration of content protection
653+
final BetterPlayerDrmConfiguration drmConfiguration;
654+
655+
///Placeholder widget which will be shown until video load or play. This
656+
///placeholder may be useful if you want to show placeholder before each video
657+
///in playlist. Otherwise, you should use placeholder from
658+
/// BetterPlayerConfiguration.
659+
final Widget placeholder;
647660
```
648661

649662

@@ -977,7 +990,12 @@ Widevine (license url based):
977990
_widevineController.setupDataSource(_widevineDataSource);
978991
979992
```
980-
993+
### Set mix audio with others
994+
You can enable mix with audio with others app with method:
995+
```dart
996+
betterPlayerController.setMixWithOthers(true)
997+
```
998+
Default value is false.
981999

9821000
### More documentation
9831001
https://pub.dev/documentation/better_player/latest/better_player/better_player-library.html

android/src/main/java/com/jhomlala/better_player/BetterPlayer.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public void onCancel(Object o) {
507507

508508
surface = new Surface(textureEntry.surfaceTexture());
509509
exoPlayer.setVideoSurface(surface);
510-
setAudioAttributes(exoPlayer);
510+
setAudioAttributes(exoPlayer, true);
511511

512512
exoPlayer.addListener(
513513
new EventListener() {
@@ -557,18 +557,18 @@ void sendBufferingUpdate() {
557557
eventSink.success(event);
558558
}
559559

560-
private static void setAudioAttributes(SimpleExoPlayer exoPlayer) {
560+
private void setAudioAttributes(SimpleExoPlayer exoPlayer, Boolean mixWithOthers) {
561561
Player.AudioComponent audioComponent = exoPlayer.getAudioComponent();
562562
if (audioComponent == null) {
563563
return;
564564
}
565565
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
566566

567567
audioComponent.setAudioAttributes(
568-
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), false);
568+
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MOVIE).build(), !mixWithOthers);
569569
} else {
570570
audioComponent.setAudioAttributes(
571-
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build(), false);
571+
new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build(), !mixWithOthers);
572572
}
573573
}
574574

@@ -788,6 +788,10 @@ private void sendSeekToEvent(long positionMs) {
788788
eventSink.success(event);
789789
}
790790

791+
public void setMixWithOthers(Boolean mixWithOthers) {
792+
setAudioAttributes(exoPlayer,mixWithOthers);
793+
}
794+
791795

792796
void dispose() {
793797
disposeMediaSession();
@@ -823,7 +827,6 @@ public int hashCode() {
823827
result = 31 * result + (surface != null ? surface.hashCode() : 0);
824828
return result;
825829
}
826-
827830
}
828831

829832

android/src/main/java/com/jhomlala/better_player/BetterPlayerPlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public class BetterPlayerPlugin implements FlutterPlugin, ActivityAware, MethodC
6666
private static final String INDEX_PARAMETER = "index";
6767
private static final String LICENSE_URL_PARAMETER = "licenseUrl";
6868
private static final String DRM_HEADERS_PARAMETER = "drmHeaders";
69+
private static final String MIX_WITH_OTHERS_PARAMETER = "mixWithOthers";
6970

7071
private static final String INIT_METHOD = "init";
7172
private static final String CREATE_METHOD = "create";
@@ -83,6 +84,7 @@ public class BetterPlayerPlugin implements FlutterPlugin, ActivityAware, MethodC
8384
private static final String ENABLE_PICTURE_IN_PICTURE_METHOD = "enablePictureInPicture";
8485
private static final String DISABLE_PICTURE_IN_PICTURE_METHOD = "disablePictureInPicture";
8586
private static final String IS_PICTURE_IN_PICTURE_SUPPORTED_METHOD = "isPictureInPictureSupported";
87+
private static final String SET_MIX_WITH_OTHERS_METHOD = "setMixWithOthers";
8688
private static final String DISPOSE_METHOD = "dispose";
8789

8890
private final LongSparseArray<BetterPlayer> videoPlayers = new LongSparseArray<>();
@@ -141,6 +143,7 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
141143
if (flutterState == null) {
142144
Log.wtf(TAG, "Detached from the engine before registering to it.");
143145
}
146+
disposeAllPlayers();
144147
BetterPlayerCache.releaseCache();
145148
flutterState.stopListening();
146149
flutterState = null;
@@ -270,7 +273,9 @@ private void onMethodCall(MethodCall call, Result result, long textureId, Better
270273
player.setAudioTrack(call.argument(NAME_PARAMETER), call.argument(INDEX_PARAMETER));
271274
result.success(null);
272275
break;
273-
276+
case SET_MIX_WITH_OTHERS_METHOD:
277+
player.setMixWithOthers(call.argument(MIX_WITH_OTHERS_PARAMETER));
278+
break;
274279
case DISPOSE_METHOD:
275280
dispose(player, textureId);
276281
result.success(null);

example/lib/main.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:flutter_localizations/flutter_localizations.dart';
55
void main() => runApp(MyApp());
66

77
class MyApp extends StatelessWidget {
8-
// This widget is the root of your application.
98
@override
109
Widget build(BuildContext context) {
1110
return MaterialApp(

example/lib/pages/playlist_page.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ class _PlaylistPageState extends State<PlaylistPage> {
1818

1919
_PlaylistPageState() {
2020
_betterPlayerConfiguration = BetterPlayerConfiguration(
21-
autoPlay: true,
2221
aspectRatio: 1,
2322
fit: BoxFit.cover,
23+
placeholderOnTop: true,
24+
showPlaceholderUntilPlay: true,
2425
subtitlesConfiguration: BetterPlayerSubtitlesConfiguration(fontSize: 10),
2526
deviceOrientationsAfterFullScreen: [
2627
DeviceOrientation.portraitUp,
@@ -29,25 +30,33 @@ class _PlaylistPageState extends State<PlaylistPage> {
2930
);
3031
_betterPlayerPlaylistConfiguration = BetterPlayerPlaylistConfiguration(
3132
loopVideos: true,
32-
nextVideoDelay: Duration(seconds: 5),
33+
nextVideoDelay: Duration(seconds: 1),
3334
);
3435
}
3536

3637
Future<List<BetterPlayerDataSource>> setupData() async {
3738
_dataSourceList.add(
3839
BetterPlayerDataSource(
39-
BetterPlayerDataSourceType.network,
40-
Constants.forBiggerBlazesUrl,
41-
subtitles: BetterPlayerSubtitlesSource.single(
42-
type: BetterPlayerSubtitlesSourceType.file,
43-
url: await Utils.getFileUrl(Constants.fileExampleSubtitlesUrl),
44-
),
45-
),
40+
BetterPlayerDataSourceType.network, Constants.forBiggerBlazesUrl,
41+
subtitles: BetterPlayerSubtitlesSource.single(
42+
type: BetterPlayerSubtitlesSourceType.file,
43+
url: await Utils.getFileUrl(Constants.fileExampleSubtitlesUrl),
44+
),
45+
placeholder: Image.network(
46+
Constants.catImageUrl,
47+
fit: BoxFit.cover,
48+
)),
4649
);
4750

4851
_dataSourceList.add(
4952
BetterPlayerDataSource(
50-
BetterPlayerDataSourceType.network, Constants.bugBuckBunnyVideoUrl),
53+
BetterPlayerDataSourceType.network,
54+
Constants.bugBuckBunnyVideoUrl,
55+
placeholder: Image.network(
56+
Constants.catImageUrl,
57+
fit: BoxFit.cover,
58+
),
59+
),
5160
);
5261
_dataSourceList.add(
5362
BetterPlayerDataSource(

example/test/widget_test.dart

Lines changed: 0 additions & 30 deletions
This file was deleted.

ios/Classes/FLTBetterPlayerPlugin.m

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ - (void)setRestoreUserInterfaceForPIPStopCompletionHandler:(BOOL)restore
649649

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

747746
}
747+
748+
}
749+
750+
- (void)setMixWithOthers:(bool)mixWithOthers {
751+
if (mixWithOthers) {
752+
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
753+
withOptions:AVAudioSessionCategoryOptionMixWithOthers
754+
error:nil];
755+
} else {
756+
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
757+
}
748758
}
749759

750760

@@ -900,6 +910,7 @@ - (void)onPlayerSetup:(FLTBetterPlayer*)player
900910
eventChannelWithName:[NSString stringWithFormat:@"better_player_channel/videoEvents%lld",
901911
textureId]
902912
binaryMessenger:_messenger];
913+
[player setMixWithOthers:false];
903914
[eventChannel setStreamHandler:player];
904915
player.eventChannel = eventChannel;
905916
_players[@(textureId)] = player;
@@ -927,7 +938,6 @@ - (void) setupRemoteNotification :(FLTBetterPlayer*) player{
927938
}
928939

929940
- (void) setRemoteCommandsNotificationActive{
930-
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
931941
[[AVAudioSession sharedInstance] setActive:true error:nil];
932942
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
933943
}
@@ -1087,7 +1097,6 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
10871097

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

12221233
else {

lib/src/configuration/better_player_cache_configuration.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class BetterPlayerCacheConfiguration {
66
///Enable cache for network data source
77
final bool useCache;
88

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

1515
/// The maximum size of each individual file in bytes.

0 commit comments

Comments
 (0)