Skip to content

Commit

Permalink
Add Hybrid composition support for Android (#314)
Browse files Browse the repository at this point in the history
* Add Hybrid composition support for Android

* Update CHANGELOG.md and bump version

Co-authored-by: tungpx <[email protected]>
  • Loading branch information
XuanTung95 and tungpx authored Apr 28, 2022
1 parent 8880453 commit 55e2753
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
3 changes: 3 additions & 0 deletions flutter_vlc_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 7.1.2
* Add Hybrid composition support for Android.

## 7.1.1
* Fixed to work on Android 6-.
Credits to Yury Kostov (https://github.com/kostov).
Expand Down
4 changes: 2 additions & 2 deletions flutter_vlc_player/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ android {
compileSdkVersion 31

defaultConfig {
minSdkVersion 17
minSdkVersion 20
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
Expand All @@ -39,7 +39,7 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'org.videolan.android:libvlc-all:3.5.0-eap4'
implementation 'org.videolan.android:libvlc-all:3.5.0-eap6'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.annotation:annotation:1.2.0'
Expand Down
7 changes: 6 additions & 1 deletion flutter_vlc_player/lib/src/flutter_vlc_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class VlcPlayer extends StatefulWidget {
final VlcPlayerController controller;
final double aspectRatio;
final Widget? placeholder;
final bool virtualDisplay;

const VlcPlayer({
Key? key,
Expand All @@ -23,6 +24,10 @@ class VlcPlayer extends StatefulWidget {
/// Before the platform view has initialized, this placeholder will be rendered instead of the video player.
/// This can simply be a [CircularProgressIndicator] (see the example.)
this.placeholder,

/// Specify whether Virtual displays or Hybrid composition is used on Android.
/// iOS only uses Hybrid composition.
this.virtualDisplay = true
}) : super(key: key);

@override
Expand Down Expand Up @@ -90,7 +95,7 @@ class _VlcPlayerState extends State<VlcPlayer>
Offstage(
offstage: !_isInitialized,
child: vlcPlayerPlatform
.buildView(widget.controller.onPlatformViewCreated),
.buildView(widget.controller.onPlatformViewCreated, virtualDisplay: widget.virtualDisplay),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions flutter_vlc_player/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_vlc_player
description: A VLC-powered alternative to Flutter's video_player. Supports multiple players on one screen.
version: 7.1.1
version: 7.1.2
homepage: https://github.com/solid-software/flutter_vlc_player/

environment:
Expand All @@ -21,7 +21,7 @@ dependencies:
sdk: flutter

meta: ^1.7.0
flutter_vlc_player_platform_interface: ^2.0.0
flutter_vlc_player_platform_interface: ^2.0.1

dev_dependencies:
flutter_test:
Expand Down
4 changes: 4 additions & 0 deletions flutter_vlc_player_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.1

- Add Hybrid composition support for Android

## 2.0.0

- Fix Dart analysis warnings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,49 @@ class MethodChannelVlcPlayer extends VlcPlayerPlatform {
/// can be rendered.
/// The `viewId` is passed as a parameter from the framework on the
/// `onPlatformViewCreated` callback.
///
/// The `virtualDisplay` specifies whether Virtual displays or Hybrid composition is used on Android.
/// iOS only uses Hybrid composition.
@override
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated) {
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated, {bool virtualDisplay = true}) {
const viewType = 'flutter_video_plugin/getVideoView';
if (Platform.isAndroid) {
return AndroidView(
viewType: 'flutter_video_plugin/getVideoView',
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
onPlatformViewCreated: onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
if (virtualDisplay) {
return AndroidView(
viewType: viewType,
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
onPlatformViewCreated: onPlatformViewCreated,
creationParamsCodec: const StandardMessageCodec(),
);
} else {
return PlatformViewLink(
viewType: viewType,
surfaceFactory: (
BuildContext context,
PlatformViewController controller,
) {
return AndroidViewSurface(
controller: controller as AndroidViewController,
gestureRecognizers: const {},
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
);
},
onCreatePlatformView: (PlatformViewCreationParams params) {
return PlatformViewsService.initSurfaceAndroidView(
id: params.id,
viewType: viewType,
layoutDirection: TextDirection.ltr,
creationParamsCodec: const StandardMessageCodec(),
)
..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
..addOnPlatformViewCreatedListener(onPlatformViewCreated)
..create();
},
);
}
} else if (Platform.isIOS) {
return UiKitView(
viewType: 'flutter_video_plugin/getVideoView',
viewType: viewType,
onPlatformViewCreated: onPlatformViewCreated,
hitTestBehavior: PlatformViewHitTestBehavior.transparent,
creationParamsCodec: const StandardMessageCodec(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class VlcPlayerPlatform extends PlatformInterface {
}

/// Returns a widget displaying the video.
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated) {
Widget buildView(PlatformViewCreatedCallback onPlatformViewCreated, {bool virtualDisplay = true}) {
throw _unimplemented('buildView');
}

Expand Down
2 changes: 1 addition & 1 deletion flutter_vlc_player_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: flutter_vlc_player_platform_interface
description: A common platform interface for the flutter vlc player plugin.
homepage: https://github.com/solid-software/flutter_vlc_player
version: 2.0.0
version: 2.0.1

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down

0 comments on commit 55e2753

Please sign in to comment.