Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support changing controller configuration #16

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/appflowy_editor_plugins/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.7

- Support providing options for HWDEC and Hardware Acceleration for the Video Block player

## 0.0.6

- Improve Video Block component
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,50 @@ import 'package:media_kit_video/media_kit_video.dart';
import 'package:provider/provider.dart';
import 'package:string_validator/string_validator.dart';

class VideoBlockConfiguration {
const VideoBlockConfiguration({
this.vo,
this.hwdec,
this.enableHardwareAcceleration = true,
this.androidAttachSurfaceAfterVideoParameters,
});

/// Sets the [`--vo`](https://mpv.io/manual/stable/#options-vo) property on native backend.
///
/// Default: Platform specific.
/// * Windows, GNU/Linux, macOS & iOS: `libmpv`
/// * Android: `gpu`
final String? vo;

/// Sets the [`--hwdec`](https://mpv.io/manual/stable/#options-hwdec) property on native backend.
///
/// Default: Platform specific.
/// * Windows, GNU/Linux, macOS & iOS : `auto`
/// * Android: `auto-safe`
final String? hwdec;

/// Whether to enable hardware acceleration.
///
/// Default: `true`
final bool enableHardwareAcceleration;

/// Whether to attach `android.view.Surface` after video parameters are known.
///
/// Default:
/// * [vo] == gpu : `true`
/// * [vo] != gpu : `false`
final bool? androidAttachSurfaceAfterVideoParameters;

VideoControllerConfiguration toControllerConfig() =>
VideoControllerConfiguration(
vo: vo,
hwdec: hwdec,
enableHardwareAcceleration: enableHardwareAcceleration,
androidAttachSurfaceAfterVideoParameters:
androidAttachSurfaceAfterVideoParameters,
);
}

typedef VoidVideoCallback = void Function(BuildContext, Node, EditorState);

class VideoBlockKit {
Expand Down Expand Up @@ -79,6 +123,7 @@ class VideoBlockComponentBuilder extends BlockComponentBuilder {
this.errorBuilder,
this.onLongPress,
this.onDoubleTap,
this.videoConfiguration = const VideoBlockConfiguration(),
});

/// Whether to show the menu of this block component.
Expand Down Expand Up @@ -112,6 +157,12 @@ class VideoBlockComponentBuilder extends BlockComponentBuilder {
///
final VoidVideoCallback? onDoubleTap;

/// The [VideoControllerConfiguration] controls certain settings
/// related to the media player, such as but not limited to:
/// - HWDEC Setting
/// - Hardware Acceleration
final VideoBlockConfiguration videoConfiguration;

@override
BlockComponentWidget build(BlockComponentContext blockComponentContext) {
final node = blockComponentContext.node;
Expand All @@ -127,6 +178,7 @@ class VideoBlockComponentBuilder extends BlockComponentBuilder {
errorBuilder: errorBuilder,
onLongPress: onLongPress,
onDoubleTap: onDoubleTap,
videoConfiguration: videoConfiguration,
);
}

Expand All @@ -147,6 +199,7 @@ class VideoBlockComponent extends BlockComponentStatefulWidget {
this.errorBuilder,
this.onLongPress,
this.onDoubleTap,
this.videoConfiguration = const VideoBlockConfiguration(),
});

/// Whether to show the menu of this block component.
Expand Down Expand Up @@ -180,6 +233,8 @@ class VideoBlockComponent extends BlockComponentStatefulWidget {
///
final VoidVideoCallback? onDoubleTap;

final VideoBlockConfiguration videoConfiguration;

@override
State<VideoBlockComponent> createState() => VideoBlockComponentState();
}
Expand All @@ -204,7 +259,10 @@ class VideoBlockComponentState extends State<VideoBlockComponent>
bool preventClose = false;

late final player = Player();
late final controller = VideoController(player);
late final controller = VideoController(
player,
configuration: widget.videoConfiguration.toControllerConfig(),
);

@override
void initState() {
Expand Down
2 changes: 1 addition & 1 deletion packages/appflowy_editor_plugins/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: appflowy_editor_plugins
description: "A collection of plugins and custom block components for the AppFlowy Editor."
version: 0.0.6
version: 0.0.7
homepage: https://github.com/AppFlowy-IO/appflowy-plugins

topics:
Expand Down
Loading