Skip to content

Commit

Permalink
feat: support changing controller configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Xazin committed May 30, 2024
1 parent ce07437 commit b6a3a56
Showing 1 changed file with 59 additions and 1 deletion.
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

0 comments on commit b6a3a56

Please sign in to comment.