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

Commit 0e4caa2

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

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

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: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,28 @@ - (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(
162+
@"Adding translation to compensate rotation. Rotation = %ld. Natural (width, height) = "
163+
@"(%f, %f)",
164+
(long)rotationDegrees, videoTrack.naturalSize.width, videoTrack.naturalSize.height);
165+
NSLog(@"Uncompensated transform (a, b, c, d, tx, ty) = (%f, %f, %f, %f, %f, %f)", transform.a,
166+
transform.b, transform.c, transform.d, transform.tx, transform.ty);
161167
if (rotationDegrees == 90) {
162-
NSLog(@"Setting transform tx");
163168
transform.tx = videoTrack.naturalSize.height;
164169
transform.ty = 0;
170+
} else if (rotationDegrees == 180) {
171+
transform.tx = videoTrack.naturalSize.width;
172+
transform.ty = videoTrack.naturalSize.height;
165173
} else if (rotationDegrees == 270) {
166-
NSLog(@"Setting transform ty");
167174
transform.tx = 0;
168175
transform.ty = videoTrack.naturalSize.width;
169176
}
177+
NSLog(@"Compensated transform (a, b, c, d, tx, ty) = (%f, %f, %f, %f, %f, %f)", transform.a,
178+
transform.b, transform.c, transform.d, transform.tx, transform.ty);
170179
}
171180
return transform;
172181
}

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 <[email protected]>
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)