Skip to content

Commit a3216f7

Browse files
committed
1 parent 97c5971 commit a3216f7

File tree

6 files changed

+41
-4
lines changed

6 files changed

+41
-4
lines changed

packages/video_player/video_player/android/src/main/java/io/flutter/plugins/videoplayer/VideoPlayer.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,17 @@ final class VideoPlayer {
9696
setupVideoPlayer(eventChannel, textureEntry);
9797
}
9898

99+
VideoPlayer(
100+
EventChannel eventChannel,
101+
TextureRegistry.SurfaceTextureEntry textureEntry,
102+
VideoPlayerOptions options,
103+
SimpleExoPlayer exoPlayer) {
104+
this.eventChannel = eventChannel;
105+
this.textureEntry = textureEntry;
106+
this.options = options;
107+
this.exoPlayer = exoPlayer;
108+
}
109+
99110
private static boolean isHTTP(Uri uri) {
100111
if (uri == null || uri.getScheme() == null) {
101112
return false;
@@ -282,6 +293,12 @@ private void sendInitialized() {
282293
}
283294
event.put("width", width);
284295
event.put("height", height);
296+
// Rotating the video with ExoPlayer does not seem to be possible with a Surface,
297+
// so inform the Flutter code that the widget needs to be rotated to prevent
298+
// upside-down playback.
299+
if (rotationDegrees == 180) {
300+
event.put("rotationCorrection", Math.PI);
301+
}
285302
}
286303
eventSink.success(event);
287304
}

packages/video_player/video_player/lib/video_player.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class VideoPlayerValue {
3939
this.isBuffering = false,
4040
this.volume = 1.0,
4141
this.playbackSpeed = 1.0,
42+
this.rotationCorrection = 0.0,
4243
this.errorDescription,
4344
});
4445

@@ -93,6 +94,9 @@ class VideoPlayerValue {
9394
/// The [size] of the currently loaded video.
9495
final Size size;
9596

97+
/// Radians to rotate the video so it is displayed correctly.
98+
final double rotationCorrection;
99+
96100
/// Indicates whether or not the video has been loaded and is ready to play.
97101
final bool isInitialized;
98102

@@ -131,6 +135,7 @@ class VideoPlayerValue {
131135
bool? isBuffering,
132136
double? volume,
133137
double? playbackSpeed,
138+
double? rotationCorrection,
134139
String? errorDescription,
135140
}) {
136141
return VideoPlayerValue(
@@ -145,6 +150,7 @@ class VideoPlayerValue {
145150
isBuffering: isBuffering ?? this.isBuffering,
146151
volume: volume ?? this.volume,
147152
playbackSpeed: playbackSpeed ?? this.playbackSpeed,
153+
rotationCorrection: rotationCorrection ?? this.rotationCorrection,
148154
errorDescription: errorDescription ?? this.errorDescription,
149155
);
150156
}
@@ -341,6 +347,7 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
341347
value = value.copyWith(
342348
duration: event.duration,
343349
size: event.size,
350+
rotationCorrection: event.rotationCorrection,
344351
isInitialized: event.duration != null,
345352
);
346353
initializingCompleter.complete(null);
@@ -693,7 +700,10 @@ class _VideoPlayerState extends State<VideoPlayer> {
693700
Widget build(BuildContext context) {
694701
return _textureId == VideoPlayerController.kUninitializedTextureId
695702
? Container()
696-
: _videoPlayerPlatform.buildView(_textureId);
703+
: Transform.rotate(
704+
angle: widget.controller.value.rotationCorrection,
705+
child: _videoPlayerPlatform.buildView(_textureId),
706+
);
697707
}
698708
}
699709

packages/video_player/video_player/pubspec.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ dependencies:
2424
flutter:
2525
sdk: flutter
2626
meta: ^1.3.0
27-
video_player_platform_interface: ^4.2.0
27+
video_player_platform_interface:
28+
path: ../video_player_platform_interface
2829
# The design on https://flutter.dev/go/federated-plugins was to leave
2930
# this constraint as "any". We cannot do it right now as it fails pub publish
3031
# validation, so we set a ^ constraint. The exact value doesn't matter since
3132
# the constraints on the interface pins it.
3233
# TODO(amirh): Revisit this (either update this part in the design or the pub tool).
3334
# https://github.com/flutter/flutter/issues/46264
34-
video_player_web: ^2.0.0
35+
video_player_web:
36+
path: ../video_player_web
3537
html: ^0.15.0
3638

3739
dev_dependencies:

packages/video_player/video_player_platform_interface/lib/method_channel_video_player.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class MethodChannelVideoPlayer extends VideoPlayerPlatform {
111111
duration: Duration(milliseconds: map['duration']),
112112
size: Size(map['width']?.toDouble() ?? 0.0,
113113
map['height']?.toDouble() ?? 0.0),
114+
rotationCorrection: map['rotationCorrection']?.toDouble() ?? 0.0,
114115
);
115116
case 'completed':
116117
return VideoEvent(

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class VideoEvent {
228228
required this.eventType,
229229
this.duration,
230230
this.size,
231+
this.rotationCorrection,
231232
this.buffered,
232233
});
233234

@@ -243,6 +244,11 @@ class VideoEvent {
243244
///
244245
/// Only used if [eventType] is [VideoEventType.initialized].
245246
final Size? size;
247+
248+
/// Radians to rotate the video so it is displayed correctly.
249+
///
250+
/// Only used if [eventType] is [VideoEventType.initialized].
251+
final double? rotationCorrection;
246252

247253
/// Buffered parts of the video.
248254
///

packages/video_player/video_player_web/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ dependencies:
2222
flutter_web_plugins:
2323
sdk: flutter
2424
meta: ^1.3.0
25-
video_player_platform_interface: ^4.2.0
25+
video_player_platform_interface:
26+
path: ../video_player_platform_interface
2627

2728
dev_dependencies:
2829
flutter_test:

0 commit comments

Comments
 (0)