diff --git a/packages/video_player/CHANGELOG.md b/packages/video_player/CHANGELOG.md index de5f66e5afd7..12e03d5e475e 100644 --- a/packages/video_player/CHANGELOG.md +++ b/packages/video_player/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.10.0+5 + +* iOS: Fixed orientation and position issue for some videos metadata. + ## 0.10.0+4 * Android: Upgrade ExoPlayer to 2.9.6. diff --git a/packages/video_player/ios/Classes/VideoPlayerPlugin.m b/packages/video_player/ios/Classes/VideoPlayerPlugin.m index cbe109bc7c35..6ac0e5dca4c9 100644 --- a/packages/video_player/ios/Classes/VideoPlayerPlugin.m +++ b/packages/video_player/ios/Classes/VideoPlayerPlugin.m @@ -154,19 +154,27 @@ - (CGAffineTransform)fixTransform:(AVAssetTrack*)videoTrack { // At least 2 user videos show a black screen when in portrait mode if we directly use the // videoTrack.preferredTransform Setting tx to the height of the video instead of 0, properly // displays the video https://github.com/flutter/flutter/issues/17606#issuecomment-413473181 - if (transform.tx == 0 && transform.ty == 0) { - NSInteger rotationDegrees = (NSInteger)round(radiansToDegrees(atan2(transform.b, transform.a))); - NSLog(@"TX and TY are 0. Rotation: %ld. Natural width,height: %f, %f", (long)rotationDegrees, - videoTrack.naturalSize.width, videoTrack.naturalSize.height); + NSInteger rotationDegrees = (NSInteger)round(radiansToDegrees(atan2(transform.b, transform.a))); + // This prevents the video to be rendered out of the screen if the metadata contain a rotation but + // no translation to compensate the shift induced by the rotation. + if (rotationDegrees != 0 && transform.tx == 0 && transform.ty == 0) { + NSLog(@"Adding translation to compensate rotation. Rotation = %ld. Natural (width, height) = " + @"(%f, %f)", + (long)rotationDegrees, videoTrack.naturalSize.width, videoTrack.naturalSize.height); + NSLog(@"Uncompensated transform (a, b, c, d, tx, ty) = (%f, %f, %f, %f, %f, %f)", transform.a, + transform.b, transform.c, transform.d, transform.tx, transform.ty); if (rotationDegrees == 90) { - NSLog(@"Setting transform tx"); transform.tx = videoTrack.naturalSize.height; transform.ty = 0; + } else if (rotationDegrees == 180) { + transform.tx = videoTrack.naturalSize.width; + transform.ty = videoTrack.naturalSize.height; } else if (rotationDegrees == 270) { - NSLog(@"Setting transform ty"); transform.tx = 0; transform.ty = videoTrack.naturalSize.width; } + NSLog(@"Compensated transform (a, b, c, d, tx, ty) = (%f, %f, %f, %f, %f, %f)", transform.a, + transform.b, transform.c, transform.d, transform.tx, transform.ty); } return transform; } diff --git a/packages/video_player/pubspec.yaml b/packages/video_player/pubspec.yaml index 5d006914ba7a..8cae1f2811ff 100644 --- a/packages/video_player/pubspec.yaml +++ b/packages/video_player/pubspec.yaml @@ -2,7 +2,7 @@ name: video_player description: Flutter plugin for displaying inline video with other Flutter widgets on Android and iOS. author: Flutter Team -version: 0.10.0+4 +version: 0.10.0+5 homepage: https://github.com/flutter/plugins/tree/master/packages/video_player flutter: