diff --git a/packages/video_player/video_player/lib/video_player.dart b/packages/video_player/video_player/lib/video_player.dart index b7ba8340fa66..6e161e80375a 100644 --- a/packages/video_player/video_player/lib/video_player.dart +++ b/packages/video_player/video_player/lib/video_player.dart @@ -270,11 +270,13 @@ class VideoPlayerController extends ValueNotifier { /// The name of the asset is given by the [dataSource] argument and must not be /// null. The [package] argument must be non-null when the asset comes from a /// package and null otherwise. - VideoPlayerController.asset(this.dataSource, - {this.package, - Future? closedCaptionFile, - this.videoPlayerOptions}) - : _closedCaptionFileFuture = closedCaptionFile, + VideoPlayerController.asset( + this.dataSource, { + this.package, + Future? closedCaptionFile, + this.videoPlayerOptions, + this.viewType = VideoViewType.textureView, + }) : _closedCaptionFileFuture = closedCaptionFile, dataSourceType = DataSourceType.asset, formatHint = null, httpHeaders = const {}, @@ -296,6 +298,7 @@ class VideoPlayerController extends ValueNotifier { Future? closedCaptionFile, this.videoPlayerOptions, this.httpHeaders = const {}, + this.viewType = VideoViewType.textureView, }) : _closedCaptionFileFuture = closedCaptionFile, dataSourceType = DataSourceType.network, package = null, @@ -316,6 +319,7 @@ class VideoPlayerController extends ValueNotifier { Future? closedCaptionFile, this.videoPlayerOptions, this.httpHeaders = const {}, + this.viewType = VideoViewType.textureView, }) : _closedCaptionFileFuture = closedCaptionFile, dataSource = url.toString(), dataSourceType = DataSourceType.network, @@ -326,11 +330,13 @@ class VideoPlayerController extends ValueNotifier { /// /// This will load the file from a file:// URI constructed from [file]'s path. /// [httpHeaders] option allows to specify HTTP headers, mainly used for hls files like (m3u8). - VideoPlayerController.file(File file, - {Future? closedCaptionFile, - this.videoPlayerOptions, - this.httpHeaders = const {}}) - : _closedCaptionFileFuture = closedCaptionFile, + VideoPlayerController.file( + File file, { + Future? closedCaptionFile, + this.videoPlayerOptions, + this.httpHeaders = const {}, + this.viewType = VideoViewType.textureView, + }) : _closedCaptionFileFuture = closedCaptionFile, dataSource = Uri.file(file.absolute.path).toString(), dataSourceType = DataSourceType.file, package = null, @@ -341,9 +347,12 @@ class VideoPlayerController extends ValueNotifier { /// /// This will load the video from the input content-URI. /// This is supported on Android only. - VideoPlayerController.contentUri(Uri contentUri, - {Future? closedCaptionFile, this.videoPlayerOptions}) - : assert(defaultTargetPlatform == TargetPlatform.android, + VideoPlayerController.contentUri( + Uri contentUri, { + Future? closedCaptionFile, + this.videoPlayerOptions, + this.viewType = VideoViewType.textureView, + }) : assert(defaultTargetPlatform == TargetPlatform.android, 'VideoPlayerController.contentUri is only supported on Android.'), _closedCaptionFileFuture = closedCaptionFile, dataSource = contentUri.toString(), @@ -376,6 +385,9 @@ class VideoPlayerController extends ValueNotifier { /// Only set for [asset] videos. The package that the asset was loaded from. final String? package; + /// The type of view used to display the video. + final VideoViewType viewType; + Future? _closedCaptionFileFuture; ClosedCaptionFile? _closedCaptionFile; Timer? _timer; @@ -877,7 +889,12 @@ class _VideoPlayerState extends State { ? Container() : _VideoPlayerWithRotation( rotation: widget.controller.value.rotationCorrection, - child: _videoPlayerPlatform.buildView(_textureId), + child: _videoPlayerPlatform.buildViewWithOptions( + VideoViewOptions( + playerId: _textureId, + viewType: widget.controller.viewType, + ), + ), ); } }