From 7bb5aa100c708f5b98b14d3004b3109bd8219cc4 Mon Sep 17 00:00:00 2001 From: Arjan Mels Date: Sat, 4 Mar 2023 11:14:48 +0100 Subject: [PATCH 1/3] Added support for video from file and assets --- .../lib/flutter_html_video.dart | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/flutter_html_video/lib/flutter_html_video.dart b/packages/flutter_html_video/lib/flutter_html_video.dart index b1ea0ca2de..583787ec75 100644 --- a/packages/flutter_html_video/lib/flutter_html_video.dart +++ b/packages/flutter_html_video/lib/flutter_html_video.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.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); @@ -54,13 +55,23 @@ class _VideoWidgetState extends State { 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: - attributes['poster'] != null && attributes['poster']!.isNotEmpty - ? Image.network(attributes['poster']!) - : Container(color: Colors.black), + placeholder: attributes['poster'] != null && attributes['poster']!.isNotEmpty + ? Image.network(attributes['poster']!) + : Container(color: Colors.black), autoPlay: attributes['autoplay'] != null, looping: attributes['loop'] != null, showControls: attributes['controls'] != null, From 05f99663df39237ba47045c03bee6b6a97993a2a Mon Sep 17 00:00:00 2001 From: Arjan Mels Date: Sat, 4 Mar 2023 11:52:52 +0100 Subject: [PATCH 2/3] Added orientation selection --- .../flutter_html_video/lib/flutter_html_video.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/flutter_html_video/lib/flutter_html_video.dart b/packages/flutter_html_video/lib/flutter_html_video.dart index 583787ec75..6c0658b09b 100644 --- a/packages/flutter_html_video/lib/flutter_html_video.dart +++ b/packages/flutter_html_video/lib/flutter_html_video.dart @@ -2,6 +2,7 @@ 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; @@ -25,11 +26,15 @@ CustomRenderMatcher videoMatcher() => (context) { class VideoWidget extends StatefulWidget { final RenderContext context; final VideoControllerCallback? callback; + final List? deviceOrientationsOnEnterFullScreen; + final List deviceOrientationsAfterFullScreen; const VideoWidget({ Key? key, required this.context, this.callback, + this.deviceOrientationsOnEnterFullScreen, + this.deviceOrientationsAfterFullScreen = DeviceOrientation.values, }) : super(key: key); @override @@ -76,8 +81,9 @@ class _VideoWidgetState extends State { looping: attributes['loop'] != null, showControls: attributes['controls'] != null, autoInitialize: true, - aspectRatio: - _width == null || _height == null ? null : _width! / _height!, + aspectRatio: _width == null || _height == null ? null : _width! / _height!, + deviceOrientationsOnEnterFullScreen: widget.deviceOrientationsOnEnterFullScreen, + deviceOrientationsAfterFullScreen: widget.deviceOrientationsAfterFullScreen, ); widget.callback?.call( widget.context.tree.element, _chewieController!, _videoController!); From 526d54c75e9939522b727aa460bf0b893e405c59 Mon Sep 17 00:00:00 2001 From: Arjan Mels Date: Sat, 4 Mar 2023 16:43:47 +0100 Subject: [PATCH 3/3] Corrected code formatting --- .../lib/flutter_html_video.dart | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/flutter_html_video/lib/flutter_html_video.dart b/packages/flutter_html_video/lib/flutter_html_video.dart index 6c0658b09b..65a018a6c8 100644 --- a/packages/flutter_html_video/lib/flutter_html_video.dart +++ b/packages/flutter_html_video/lib/flutter_html_video.dart @@ -66,24 +66,30 @@ class _VideoWidgetState extends State { _videoController = VideoPlayerController.asset(sourceUri.path); break; case 'file': - _videoController = VideoPlayerController.file(File.fromUri(sourceUri)); + _videoController = + VideoPlayerController.file(File.fromUri(sourceUri)); break; default: - _videoController = VideoPlayerController.network(sourceUri.toString()); + _videoController = + VideoPlayerController.network(sourceUri.toString()); break; } _chewieController = ChewieController( videoPlayerController: _videoController!, - placeholder: attributes['poster'] != null && attributes['poster']!.isNotEmpty - ? Image.network(attributes['poster']!) - : Container(color: Colors.black), + placeholder: + attributes['poster'] != null && attributes['poster']!.isNotEmpty + ? Image.network(attributes['poster']!) + : Container(color: Colors.black), autoPlay: attributes['autoplay'] != null, looping: attributes['loop'] != null, showControls: attributes['controls'] != null, autoInitialize: true, - aspectRatio: _width == null || _height == null ? null : _width! / _height!, - deviceOrientationsOnEnterFullScreen: widget.deviceOrientationsOnEnterFullScreen, - deviceOrientationsAfterFullScreen: widget.deviceOrientationsAfterFullScreen, + aspectRatio: + _width == null || _height == null ? null : _width! / _height!, + deviceOrientationsOnEnterFullScreen: + widget.deviceOrientationsOnEnterFullScreen, + deviceOrientationsAfterFullScreen: + widget.deviceOrientationsAfterFullScreen, ); widget.callback?.call( widget.context.tree.element, _chewieController!, _videoController!);