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

[video_player] Fix aspect ratio #690

Merged
merged 48 commits into from
Jan 24, 2019

Conversation

recastrodiaz
Copy link
Contributor

@recastrodiaz recastrodiaz commented Jul 28, 2018

This PR adds a rotationDegrees field to the VideoPlayerValue class and fixes the aspectRatio field so it takes the rotation of the video into account. This ensures that videos are properly displayed when wrapped with an AspectRatio Widget. (Currently portrait videos look squashed).

  • Android videos were no longer displayed with the correct aspect ratio when running against the new ExoPlayer. This seems to be a regression introduced in video_player v0.6.0.
  • iOS videos were never shown with the correct aspect ratio in portrait mode (Adding Video Capability to image_picker #565 (comment))

Test Methodology:

  • Android:
    • Took 4 videos with a Samsung S6 camera in all 4 possible orientations. Took 4 more videos in All 4 possible orientations with the frontal camera
    • Ran the image_picker example and validated all 8 videos displayed correctly (cd packages/image_picker/example && flutter run)
  • iOS:
    • Same approach as above. 8 videos recorded with the default iOS app on an iPhone 4s

This PR fixes flutter/flutter#17606.

…ssible values are: 0, 90, 180 and 270.

* Updated the aspectRatio getter to use the video rotation.
* Fixed the aspect ratio of videos in the video_player plugin example. It now properly displays 'rotated' videos.
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

@recastrodiaz
Copy link
Contributor Author

I signed it!

@googlebot
Copy link

CLAs look good, thanks!

…_player plugin on iOS devices. The fix sets the videoComposition of the respective AVPlayerItem to use the preferredTransform of the video (the rotation matrix for the video)
…_player plugin on iOS devices. The fix sets the videoComposition of the respective AVPlayerItem to use the preferredTransform of the video (the rotation matrix for the video)
@recastrodiaz recastrodiaz changed the title [WIP] Fix video player aspect ratio Fix video player aspect ratio Aug 13, 2018
…tion in Android (possibly happening in iOS too)
…deo is in portratit mode then height > width
…e. Plus remove extra sendInitialized call

- Add support for playing PHAssets from localIdentifier. Currently used from flutter like File('phasset://LOCAL_IDENTIFIER')
…ot have the tx and ty values populated, which in turn renders black videos. We work around this by settings the tx and ty values ourselves
@cbracken
Copy link
Member

cbracken commented Sep 6, 2018

Apologies for the delay in getting to this PR. We're slowly making our way through. I'll take a look at this in the next few days. Thanks for your contribution!

@recastrodiaz
Copy link
Contributor Author

Thanks @cbracken! Looking forward to your review.

@ghost
Copy link

ghost commented Dec 10, 2018

@mnazim You can meanwhile use this like so I just tried that and worked perfectly!

  video_player:
    git:
      url: https://github.com/recastrodiaz/plugins.git
      path: packages/video_player  
      ref: 42ad92ffeab0f78baae289757e0ea121491b0c60
    version: ^0.7.3

@ghost
Copy link

ghost commented Dec 11, 2018

What is going on with 0.8.0 aspectRatio is not fixed at all.

@rlee1990
Copy link

Any updates on this?

@uiboy
Copy link

uiboy commented Dec 21, 2018

@recastrodiaz I was testing network videos with this PR and I run into this error, I understand that this only fixes file videos, but I think it should still at least display network videos correctly.

NoSuchMethodError: The method 'toInt' was called on null. Receiver: null Tried calling: toInt() #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:50:5) #1 VideoPlayerController.initialize.eventListener (package:video_player/video_player.dart:245:53) #2 _RootZone.runUnaryGuarded (dart:async/zone.dart:1314:10) #3 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:336:11) #4 _DelayedData.perform (dart:async/stream_impl.dart:591:14) #5 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:707:11) #6 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:667:7) #7 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) #8 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

The offending line seems to be 245 in video_player which has
rotationDegrees: map['rotationDegrees'].toInt() ?? 0.0,

It seems map['rotationDegrees'] is null.. I also could not find a setRotationDegrees method but I assume this is intended to be handled internally that is why.

Any clues on why this would be happening ?

my pubspec.yml:

video_player:
    git:
      url: https://github.com/recastrodiaz/plugins.git
      path: packages/video_player
      ref: 42ad92ffeab0f78baae289757e0ea121491b0c60
    version: ^0.7.3

@recastrodiaz
Copy link
Contributor Author

@uiboy 42ad92 is a very old revision. Can you check if the latest commit also throws an error?

ref: d589ee54ce405e38ebc42b1961e54273cd375726

@uiboy
Copy link

uiboy commented Dec 28, 2018

@recastrodiaz oops my bad, yes that seems to work. Thanks for your response. Happy Holidays!

@ghost
Copy link

ghost commented Dec 28, 2018

@recastrodiaz
I tried to get like so.

  video_player:
    git:
      url: https://github.com/recastrodiaz/plugins.git
      path: packages/video_player  
      ref: d589ee54ce405e38ebc42b1961e54273cd375726
    version: ^0.7.3

But error saying

Because MyApp depends on video_player ^0.7.3 from git which doesn't match any versions, version solving failed.
pub get failed (1)
exit code 1

Any idea?
Thanks for your work!

@ghost
Copy link

ghost commented Dec 28, 2018

@uiboy Could you share your pubspec.yml?

@uiboy
Copy link

uiboy commented Dec 28, 2018

@Tj543 I have this in my pubspec.yml (0.8.0) , maybe that is why it doesnt work for you.

  video_player:
    git:
      url: https://github.com/recastrodiaz/plugins.git
      path: packages/video_player
      ref: d589ee54ce405e38ebc42b1961e54273cd375726
    version: ^0.8.0

- addListener is not required to render the first video frame
- call setState() on play/pause to update the UI
- dispose() the controller when the widget is disposed
- fix video urls
@dnfield
Copy link
Contributor

dnfield commented Jan 24, 2019

Can you merge this in with master to get CI doing what it needs to?

Sorry for the delay again. We haven't lost track of this (completely)!

_controller.value.isPlaying
? _controller.pause()
: _controller.play();
setState(() {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we calling setState empty here? Can we either move the lines above this to the closure for setState, or comment on the unusual use of setState here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move them inside the setState. We need setState as otherwise the play/pause button UI does not get updated.

@@ -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 <flutter-dev@googlegroups.com>
version: 0.8.0
version: 0.8.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a 0.9.0 bump? Could we end up surprising anyone with this change if they had some other work around in place to handle it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Updated to 0.9.0

@dnfield
Copy link
Contributor

dnfield commented Jan 24, 2019

Just a couple small things and a merge (or rebase) needed, and this should be good to go.

- Move play/pause logic within setState closure in video_player example
@recastrodiaz
Copy link
Contributor Author

@dnfield Thanks for looking at this again! Very much appreciated! Any other issues please let me know.

@dnfield
Copy link
Contributor

dnfield commented Jan 24, 2019

LGTM

@dnfield dnfield merged commit 014e373 into flutter:master Jan 24, 2019
@recastrodiaz recastrodiaz deleted the video_player_aspectratio branch January 24, 2019 17:02
@franzejr
Copy link

Hey @recastrodiaz , the version 0.9.0 is not here: https://pub.dartlang.org/packages/video_player#-versions-tab- ?

@dnfield
Copy link
Contributor

dnfield commented Feb 14, 2019

The latest version on pub should have this change. Looks like no one ever published 0.9.0 but we can fix that.

@dnfield
Copy link
Contributor

dnfield commented Feb 14, 2019

@mklim has taken care of this - 0.9.0 is now available on pub. See flutter/flutter#27258 - we're working on making sure these don't get missed in the future.

andreidiaconu pushed a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
* * Added access to the video rotation in degrees (rotationDegrees). Possible values are: 0, 90, 180 and 270.
* Updated the aspectRatio getter to use the video rotation.
* Fixed the aspect ratio of videos in the video_player plugin example. It now properly displays 'rotated' videos.
* Ensure videos are not upside down nor streteched when using the video_player plugin on iOS devices. The fix sets the videoComposition of the respective AVPlayerItem to use the preferredTransform of the video (the rotation matrix for the video)

* - Bump video_player version to 0.9.0
- Move play/pause logic within setState closure in video_player example
andreidiaconu added a commit to andreidiaconu/plugins that referenced this pull request Feb 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

video_player aspect ratio and orientation messed up on iOS
10 participants