Skip to content

Improve video #1236

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

Merged
merged 3 commits into from
May 9, 2023
Merged
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
25 changes: 24 additions & 1 deletion packages/flutter_html_video/lib/flutter_html_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ library flutter_html_video;

import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:video_player/video_player.dart';
import 'package:html/dom.dart' as dom;
import 'dart:io';

typedef VideoControllerCallback = void Function(
dom.Element?, ChewieController, VideoPlayerController);
Expand All @@ -24,11 +26,15 @@ CustomRenderMatcher videoMatcher() => (context) {
class VideoWidget extends StatefulWidget {
final RenderContext context;
final VideoControllerCallback? callback;
final List<DeviceOrientation>? deviceOrientationsOnEnterFullScreen;
final List<DeviceOrientation> deviceOrientationsAfterFullScreen;

const VideoWidget({
Key? key,
required this.context,
this.callback,
this.deviceOrientationsOnEnterFullScreen,
this.deviceOrientationsAfterFullScreen = DeviceOrientation.values,
}) : super(key: key);

@override
Expand All @@ -54,7 +60,20 @@ class _VideoWidgetState extends State<VideoWidget> {
if (sources.isNotEmpty && sources.first != null) {
_width = givenWidth ?? (givenHeight ?? 150) * 2;
_height = givenHeight ?? (givenWidth ?? 300) / 2;
_videoController = VideoPlayerController.network(sources.first!);
Uri sourceUri = Uri.parse(sources.first!);
switch (sourceUri.scheme) {
case 'asset':
_videoController = VideoPlayerController.asset(sourceUri.path);
break;
case 'file':
_videoController =
VideoPlayerController.file(File.fromUri(sourceUri));
break;
default:
_videoController =
VideoPlayerController.network(sourceUri.toString());
break;
}
_chewieController = ChewieController(
videoPlayerController: _videoController!,
placeholder:
Expand All @@ -67,6 +86,10 @@ class _VideoWidgetState extends State<VideoWidget> {
autoInitialize: true,
aspectRatio:
_width == null || _height == null ? null : _width! / _height!,
deviceOrientationsOnEnterFullScreen:
widget.deviceOrientationsOnEnterFullScreen,
deviceOrientationsAfterFullScreen:
widget.deviceOrientationsAfterFullScreen,
);
widget.callback?.call(
widget.context.tree.element, _chewieController!, _videoController!);
Expand Down