44
55import 'dart:async' ;
66import 'dart:io' ;
7+ import 'dart:math' as math;
78
89import 'package:flutter/foundation.dart' ;
910import 'package:flutter/material.dart' ;
@@ -48,6 +49,7 @@ class VideoPlayerValue {
4849 this .isBuffering = false ,
4950 this .volume = 1.0 ,
5051 this .playbackSpeed = 1.0 ,
52+ this .rotationCorrection = 0 ,
5153 this .errorDescription,
5254 });
5355
@@ -111,6 +113,9 @@ class VideoPlayerValue {
111113 /// The [size] of the currently loaded video.
112114 final Size size;
113115
116+ /// Degrees to rotate the video (clockwise) so it is displayed correctly.
117+ final int rotationCorrection;
118+
114119 /// Indicates whether or not the video has been loaded and is ready to play.
115120 final bool isInitialized;
116121
@@ -136,7 +141,7 @@ class VideoPlayerValue {
136141 }
137142
138143 /// Returns a new instance that has the same values as this current instance,
139- /// except for any overrides passed in as arguments to [copyWidth ] .
144+ /// except for any overrides passed in as arguments to [copyWith ] .
140145 VideoPlayerValue copyWith ({
141146 Duration ? duration,
142147 Size ? size,
@@ -150,6 +155,7 @@ class VideoPlayerValue {
150155 bool ? isBuffering,
151156 double ? volume,
152157 double ? playbackSpeed,
158+ int ? rotationCorrection,
153159 String ? errorDescription = _defaultErrorDescription,
154160 }) {
155161 return VideoPlayerValue (
@@ -165,6 +171,7 @@ class VideoPlayerValue {
165171 isBuffering: isBuffering ?? this .isBuffering,
166172 volume: volume ?? this .volume,
167173 playbackSpeed: playbackSpeed ?? this .playbackSpeed,
174+ rotationCorrection: rotationCorrection ?? this .rotationCorrection,
168175 errorDescription: errorDescription != _defaultErrorDescription
169176 ? errorDescription
170177 : this .errorDescription,
@@ -368,6 +375,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
368375 value = value.copyWith (
369376 duration: event.duration,
370377 size: event.size,
378+ rotationCorrection: event.rotationCorrection,
371379 isInitialized: event.duration != null ,
372380 errorDescription: null ,
373381 );
@@ -761,10 +769,29 @@ class _VideoPlayerState extends State<VideoPlayer> {
761769 Widget build (BuildContext context) {
762770 return _textureId == VideoPlayerController .kUninitializedTextureId
763771 ? Container ()
764- : _videoPlayerPlatform.buildView (_textureId);
772+ : _VideoPlayerWithRotation (
773+ rotation: widget.controller.value.rotationCorrection,
774+ child: _videoPlayerPlatform.buildView (_textureId),
775+ );
765776 }
766777}
767778
779+ class _VideoPlayerWithRotation extends StatelessWidget {
780+ const _VideoPlayerWithRotation (
781+ {Key ? key, required this .rotation, required this .child})
782+ : super (key: key);
783+ final int rotation;
784+ final Widget child;
785+
786+ @override
787+ Widget build (BuildContext context) => rotation == 0
788+ ? child
789+ : Transform .rotate (
790+ angle: rotation * math.pi / 180 ,
791+ child: child,
792+ );
793+ }
794+
768795/// Used to configure the [VideoProgressIndicator] widget's colors for how it
769796/// describes the video's status.
770797///
0 commit comments