Skip to content

Commit 55e2753

Browse files
XuanTung95tungpx
andauthored
Add Hybrid composition support for Android (#314)
* Add Hybrid composition support for Android * Update CHANGELOG.md and bump version Co-authored-by: tungpx <[email protected]>
1 parent 8880453 commit 55e2753

File tree

8 files changed

+58
-15
lines changed

8 files changed

+58
-15
lines changed

flutter_vlc_player/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 7.1.2
2+
* Add Hybrid composition support for Android.
3+
14
## 7.1.1
25
* Fixed to work on Android 6-.
36
Credits to Yury Kostov (https://github.com/kostov).

flutter_vlc_player/android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android {
2525
compileSdkVersion 31
2626

2727
defaultConfig {
28-
minSdkVersion 17
28+
minSdkVersion 20
2929
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3030
}
3131
lintOptions {
@@ -39,7 +39,7 @@ android {
3939

4040
dependencies {
4141
implementation fileTree(include: ['*.jar'], dir: 'libs')
42-
implementation 'org.videolan.android:libvlc-all:3.5.0-eap4'
42+
implementation 'org.videolan.android:libvlc-all:3.5.0-eap6'
4343
implementation 'androidx.appcompat:appcompat:1.2.0'
4444
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
4545
implementation 'androidx.annotation:annotation:1.2.0'

flutter_vlc_player/lib/src/flutter_vlc_player.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class VlcPlayer extends StatefulWidget {
77
final VlcPlayerController controller;
88
final double aspectRatio;
99
final Widget? placeholder;
10+
final bool virtualDisplay;
1011

1112
const VlcPlayer({
1213
Key? key,
@@ -23,6 +24,10 @@ class VlcPlayer extends StatefulWidget {
2324
/// Before the platform view has initialized, this placeholder will be rendered instead of the video player.
2425
/// This can simply be a [CircularProgressIndicator] (see the example.)
2526
this.placeholder,
27+
28+
/// Specify whether Virtual displays or Hybrid composition is used on Android.
29+
/// iOS only uses Hybrid composition.
30+
this.virtualDisplay = true
2631
}) : super(key: key);
2732

2833
@override
@@ -90,7 +95,7 @@ class _VlcPlayerState extends State<VlcPlayer>
9095
Offstage(
9196
offstage: !_isInitialized,
9297
child: vlcPlayerPlatform
93-
.buildView(widget.controller.onPlatformViewCreated),
98+
.buildView(widget.controller.onPlatformViewCreated, virtualDisplay: widget.virtualDisplay),
9499
),
95100
],
96101
),

flutter_vlc_player/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_vlc_player
22
description: A VLC-powered alternative to Flutter's video_player. Supports multiple players on one screen.
3-
version: 7.1.1
3+
version: 7.1.2
44
homepage: https://github.com/solid-software/flutter_vlc_player/
55

66
environment:
@@ -21,7 +21,7 @@ dependencies:
2121
sdk: flutter
2222

2323
meta: ^1.7.0
24-
flutter_vlc_player_platform_interface: ^2.0.0
24+
flutter_vlc_player_platform_interface: ^2.0.1
2525

2626
dev_dependencies:
2727
flutter_test:

flutter_vlc_player_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
3+
- Add Hybrid composition support for Android
4+
15
## 2.0.0
26

37
- Fix Dart analysis warnings

flutter_vlc_player_platform_interface/lib/src/method_channel/method_channel_vlc_player.dart

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,49 @@ class MethodChannelVlcPlayer extends VlcPlayerPlatform {
5757
/// can be rendered.
5858
/// The `viewId` is passed as a parameter from the framework on the
5959
/// `onPlatformViewCreated` callback.
60+
///
61+
/// The `virtualDisplay` specifies whether Virtual displays or Hybrid composition is used on Android.
62+
/// iOS only uses Hybrid composition.
6063
@override
61-
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated) {
64+
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated, {bool virtualDisplay = true}) {
65+
const viewType = 'flutter_video_plugin/getVideoView';
6266
if (Platform.isAndroid) {
63-
return AndroidView(
64-
viewType: 'flutter_video_plugin/getVideoView',
65-
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
66-
onPlatformViewCreated: onPlatformViewCreated,
67-
creationParamsCodec: const StandardMessageCodec(),
68-
);
67+
if (virtualDisplay) {
68+
return AndroidView(
69+
viewType: viewType,
70+
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
71+
onPlatformViewCreated: onPlatformViewCreated,
72+
creationParamsCodec: const StandardMessageCodec(),
73+
);
74+
} else {
75+
return PlatformViewLink(
76+
viewType: viewType,
77+
surfaceFactory: (
78+
BuildContext context,
79+
PlatformViewController controller,
80+
) {
81+
return AndroidViewSurface(
82+
controller: controller as AndroidViewController,
83+
gestureRecognizers: const {},
84+
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
85+
);
86+
},
87+
onCreatePlatformView: (PlatformViewCreationParams params) {
88+
return PlatformViewsService.initSurfaceAndroidView(
89+
id: params.id,
90+
viewType: viewType,
91+
layoutDirection: TextDirection.ltr,
92+
creationParamsCodec: const StandardMessageCodec(),
93+
)
94+
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
95+
..addOnPlatformViewCreatedListener(onPlatformViewCreated)
96+
..create();
97+
},
98+
);
99+
}
69100
} else if (Platform.isIOS) {
70101
return UiKitView(
71-
viewType: 'flutter_video_plugin/getVideoView',
102+
viewType: viewType,
72103
onPlatformViewCreated: onPlatformViewCreated,
73104
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
74105
creationParamsCodec: const StandardMessageCodec(),

flutter_vlc_player_platform_interface/lib/src/platform_interface/vlc_player_platform_interface.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ abstract class VlcPlayerPlatform extends PlatformInterface {
3333
}
3434

3535
/// Returns a widget displaying the video.
36-
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated) {
36+
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated, {bool virtualDisplay = true}) {
3737
throw _unimplemented('buildView');
3838
}
3939

flutter_vlc_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_vlc_player_platform_interface
22
description: A common platform interface for the flutter vlc player plugin.
33
homepage: https://github.com/solid-software/flutter_vlc_player
4-
version: 2.0.0
4+
version: 2.0.1
55

66
environment:
77
sdk: '>=2.12.0 <3.0.0'

0 commit comments

Comments
 (0)