Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a6de6a7

Browse files
[video_player] Fixed orientation and position issue for some videos metadata.
1 parent 8c180f0 commit a6de6a7

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

packages/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.0+5
2+
3+
* iOS: Fixed orientation and position issue for some videos metadata.
4+
15
## 0.10.0+4
26

37
* Android: Upgrade ExoPlayer to 2.9.6.

packages/video_player/ios/Classes/VideoPlayerPlugin.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,27 @@ - (CGAffineTransform)fixTransform:(AVAssetTrack*)videoTrack {
154154
// At least 2 user videos show a black screen when in portrait mode if we directly use the
155155
// videoTrack.preferredTransform Setting tx to the height of the video instead of 0, properly
156156
// displays the video https://github.com/flutter/flutter/issues/17606#issuecomment-413473181
157-
if (transform.tx == 0 && transform.ty == 0) {
158-
NSInteger rotationDegrees = (NSInteger)round(radiansToDegrees(atan2(transform.b, transform.a)));
159-
NSLog(@"TX and TY are 0. Rotation: %ld. Natural width,height: %f, %f", (long)rotationDegrees,
160-
videoTrack.naturalSize.width, videoTrack.naturalSize.height);
157+
NSInteger rotationDegrees = (NSInteger)round(radiansToDegrees(atan2(transform.b, transform.a)));
158+
// This prevents the video to be rendered out of the screen if the metadata contain a rotation but
159+
// no translation to compensate the shift induced by the rotation.
160+
if (rotationDegrees != 0 && transform.tx == 0 && transform.ty == 0) {
161+
NSLog(@"Adding translation to compensate rotation. Rotation = %ld. Natural (width, height) = "
162+
@"(%f, %f)",
163+
(long)rotationDegrees, videoTrack.naturalSize.width, videoTrack.naturalSize.height);
164+
NSLog(@"Uncompensated transform (a, b, c, d, tx, ty) = (%f, %f, %f, %f, %f, %f)", transform.a,
165+
transform.b, transform.c, transform.d, transform.tx, transform.ty);
161166
if (rotationDegrees == 90) {
162-
NSLog(@"Setting transform tx");
163167
transform.tx = videoTrack.naturalSize.height;
164168
transform.ty = 0;
169+
} else if (rotationDegrees == 180) {
170+
transform.tx = videoTrack.naturalSize.width;
171+
transform.ty = videoTrack.naturalSize.height;
165172
} else if (rotationDegrees == 270) {
166-
NSLog(@"Setting transform ty");
167173
transform.tx = 0;
168174
transform.ty = videoTrack.naturalSize.width;
169175
}
176+
NSLog(@"Compensated transform (a, b, c, d, tx, ty) = (%f, %f, %f, %f, %f, %f)", transform.a,
177+
transform.b, transform.c, transform.d, transform.tx, transform.ty);
170178
}
171179
return transform;
172180
}

packages/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player
22
description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android and iOS.
44
author: Flutter Team <flutter-dev@googlegroups.com>
5-
version: 0.10.0+4
5+
version: 0.10.0+5
66
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player
77

88
flutter:

0 commit comments

Comments
 (0)