@@ -187,27 +187,26 @@ - (instancetype)initWithURL:(NSURL *)url
187
187
return [self initWithPlayerItem: item frameUpdater: frameUpdater];
188
188
}
189
189
190
+ // Fix the transform for the given track accordingly.
191
+ // See also: https://stackoverflow.com/a/64161545/13235500
190
192
- (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 ;
209
208
}
210
- return transform ;
209
+ return t ;
211
210
}
212
211
213
212
- (instancetype )initWithPlayerItem : (AVPlayerItem *)item
0 commit comments