Skip to content

Commit

Permalink
Add viewType parameter to VideoPlayerController and use it to display…
Browse files Browse the repository at this point in the history
… view
  • Loading branch information
FirentisTFW committed Nov 26, 2024
1 parent d6724d9 commit eae938d
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
/// 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>? closedCaptionFile,
this.videoPlayerOptions})
: _closedCaptionFileFuture = closedCaptionFile,
VideoPlayerController.asset(
this.dataSource, {
this.package,
Future<ClosedCaptionFile>? closedCaptionFile,
this.videoPlayerOptions,
this.viewType = VideoViewType.textureView,
}) : _closedCaptionFileFuture = closedCaptionFile,
dataSourceType = DataSourceType.asset,
formatHint = null,
httpHeaders = const <String, String>{},
Expand All @@ -296,6 +298,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
Future<ClosedCaptionFile>? closedCaptionFile,
this.videoPlayerOptions,
this.httpHeaders = const <String, String>{},
this.viewType = VideoViewType.textureView,
}) : _closedCaptionFileFuture = closedCaptionFile,
dataSourceType = DataSourceType.network,
package = null,
Expand All @@ -316,6 +319,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
Future<ClosedCaptionFile>? closedCaptionFile,
this.videoPlayerOptions,
this.httpHeaders = const <String, String>{},
this.viewType = VideoViewType.textureView,
}) : _closedCaptionFileFuture = closedCaptionFile,
dataSource = url.toString(),
dataSourceType = DataSourceType.network,
Expand All @@ -326,11 +330,13 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
///
/// 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>? closedCaptionFile,
this.videoPlayerOptions,
this.httpHeaders = const <String, String>{}})
: _closedCaptionFileFuture = closedCaptionFile,
VideoPlayerController.file(
File file, {
Future<ClosedCaptionFile>? closedCaptionFile,
this.videoPlayerOptions,
this.httpHeaders = const <String, String>{},
this.viewType = VideoViewType.textureView,
}) : _closedCaptionFileFuture = closedCaptionFile,
dataSource = Uri.file(file.absolute.path).toString(),
dataSourceType = DataSourceType.file,
package = null,
Expand All @@ -341,9 +347,12 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
///
/// This will load the video from the input content-URI.
/// This is supported on Android only.
VideoPlayerController.contentUri(Uri contentUri,
{Future<ClosedCaptionFile>? closedCaptionFile, this.videoPlayerOptions})
: assert(defaultTargetPlatform == TargetPlatform.android,
VideoPlayerController.contentUri(
Uri contentUri, {
Future<ClosedCaptionFile>? closedCaptionFile,
this.videoPlayerOptions,
this.viewType = VideoViewType.textureView,
}) : assert(defaultTargetPlatform == TargetPlatform.android,
'VideoPlayerController.contentUri is only supported on Android.'),
_closedCaptionFileFuture = closedCaptionFile,
dataSource = contentUri.toString(),
Expand Down Expand Up @@ -376,6 +385,9 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
/// 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<ClosedCaptionFile>? _closedCaptionFileFuture;
ClosedCaptionFile? _closedCaptionFile;
Timer? _timer;
Expand Down Expand Up @@ -877,7 +889,12 @@ class _VideoPlayerState extends State<VideoPlayer> {
? Container()
: _VideoPlayerWithRotation(
rotation: widget.controller.value.rotationCorrection,
child: _videoPlayerPlatform.buildView(_textureId),
child: _videoPlayerPlatform.buildViewWithOptions(
VideoViewOptions(
playerId: _textureId,
viewType: widget.controller.viewType,
),
),
);
}
}
Expand Down

0 comments on commit eae938d

Please sign in to comment.