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

Commit 7c1211e

Browse files
committed
Apply transform accordingly for videos
1 parent 04f64ec commit 7c1211e

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

packages/video_player/video_player_avfoundation/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.2
2+
3+
* Apply transform accordingly for videos.
4+
15
## 2.3.1
26

37
* Renames internal method channels to avoid potential confusion with the

packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,27 +187,26 @@ - (instancetype)initWithURL:(NSURL *)url
187187
return [self initWithPlayerItem:item frameUpdater:frameUpdater];
188188
}
189189

190+
// Fix the transform for the given track accordingly.
191+
// See also: https://stackoverflow.com/a/64161545/13235500
190192
- (CGAffineTransform)fixTransform:(AVAssetTrack *)videoTrack {
191-
CGAffineTransform transform = videoTrack.preferredTransform;
192-
// TODO(@recastrodiaz): why do we need to do this? Why is the preferredTransform incorrect?
193-
// At least 2 user videos show a black screen when in portrait mode if we directly use the
194-
// videoTrack.preferredTransform Setting tx to the height of the video instead of 0, properly
195-
// displays the video https://github.com/flutter/flutter/issues/17606#issuecomment-413473181
196-
if (transform.tx == 0 && transform.ty == 0) {
197-
NSInteger rotationDegrees = (NSInteger)round(radiansToDegrees(atan2(transform.b, transform.a)));
198-
NSLog(@"TX and TY are 0. Rotation: %ld. Natural width,height: %f, %f", (long)rotationDegrees,
199-
videoTrack.naturalSize.width, videoTrack.naturalSize.height);
200-
if (rotationDegrees == 90) {
201-
NSLog(@"Setting transform tx");
202-
transform.tx = videoTrack.naturalSize.height;
203-
transform.ty = 0;
204-
} else if (rotationDegrees == 270) {
205-
NSLog(@"Setting transform ty");
206-
transform.tx = 0;
207-
transform.ty = videoTrack.naturalSize.width;
208-
}
193+
CGAffineTransform t = videoTrack.preferredTransform;
194+
CGSize size = videoTrack.naturalSize;
195+
t.tx = 0;
196+
t.ty = 0;
197+
if (t.a == -1) {
198+
t.tx = size.width;
199+
}
200+
if (t.b == -1) {
201+
t.ty = size.width;
202+
}
203+
if (t.c == -1) {
204+
t.tx = size.height;
205+
}
206+
if (t.d == -1) {
207+
t.ty = size.height;
209208
}
210-
return transform;
209+
return t;
211210
}
212211

213212
- (instancetype)initWithPlayerItem:(AVPlayerItem *)item

packages/video_player/video_player_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avfoundation
22
description: iOS implementation of the video_player plugin.
33
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.3.1
5+
version: 2.3.2
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

0 commit comments

Comments
 (0)